Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forced program exit ??

Status
Not open for further replies.

alanshort

Programmer
Jan 23, 2004
5
GB
I've written a small app which downloads a file from the internet then parses it.

If the file cannot be downloaded, the execption is caught and it calls its self again for another try. (however, this will go on forever)

i'm using for example

public static void getFile()
{

string fileToGet = " ;
string fileToPut = "myFolder/afile.txt" ;

try
{
WebClient Client = new WebClient();
Client.DownloadFile(fileToGet, fileToPut);
}
catch (Exception exp) {getFile();}

}

what i would like to do is try say 5 times then if it still can't download then quit the program...

Is there a forced exit command in C# that will just quit the program and do nothing else ??
 
You have to remove the call of the getFile() from the catch block and restructure your code in a loop of executing the getFile() maximum 5 times if there are errors.
If your application has a form then call Form.Close() before calling Application.Exit() which will stop the app.
If your code is in Thread then call Thread.Stop() to stop the downloading thread after you tried 5 times.
-obislavu-


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top