A
Asad
Hi,
I am trying to write some threading code to my application. The reason
I've been tempted to do this is because, I am doing some FTP uploads,
and sometimes during the put method, the application just hangs ("Not
Responding") instead of the regular timeout and return. I am using a
library to perform FTP stuff and so there may be a bug in there. In
any case, what I am concerned with is my application executing with
graceful execution and termination. I have plenty of try and catch
clauses inside the methods, and I even know which line is causing the
problem (the put line), I even tried debugging it line by line, but
sometimes it just hangs up. This is happening with only this one
particular FTP server being run by a client.
So, I am thinking if I should create a thread that calls the
doFTPUpload method. If the method doesn't return within, say, 60
seconds, I forcefully terminate the call and show an error to the user
via GUI. The main idea is to keep the application from going into "Not
Responding" state by running the error prone code in a different
thread.
Now I have never done threading before but have read about it. So I am
hoping someone can push me in the right direction.
I have a class called Transmission that has doFTPUpload method. It
takes in three arguments, a client object (that contains information
about the FTP such as server name, user id, password, etc.),a logs
object which is used to enter information into log files, and a
textbox txtSummary which shows information to user as upload
progresses.
I make a call from my main method as follows:
try
{
t.doFTPUpload(client,logs,txtSummary);
}
catch (Exception eUpload)
{
logs.addToLog("Upload Failed!");
logs.addToLog(eUpload.ToString());
}
Now how can I modify this code to start a new worker thread and make
the call to doFTPUpload inside this thread. Also how can I put a
timeout on it so that if the thread doesn't finish up in say 60
seconds, I manually kill the thread and go on with my execution inside
the main method?
Thanks.
Asad
I am trying to write some threading code to my application. The reason
I've been tempted to do this is because, I am doing some FTP uploads,
and sometimes during the put method, the application just hangs ("Not
Responding") instead of the regular timeout and return. I am using a
library to perform FTP stuff and so there may be a bug in there. In
any case, what I am concerned with is my application executing with
graceful execution and termination. I have plenty of try and catch
clauses inside the methods, and I even know which line is causing the
problem (the put line), I even tried debugging it line by line, but
sometimes it just hangs up. This is happening with only this one
particular FTP server being run by a client.
So, I am thinking if I should create a thread that calls the
doFTPUpload method. If the method doesn't return within, say, 60
seconds, I forcefully terminate the call and show an error to the user
via GUI. The main idea is to keep the application from going into "Not
Responding" state by running the error prone code in a different
thread.
Now I have never done threading before but have read about it. So I am
hoping someone can push me in the right direction.
I have a class called Transmission that has doFTPUpload method. It
takes in three arguments, a client object (that contains information
about the FTP such as server name, user id, password, etc.),a logs
object which is used to enter information into log files, and a
textbox txtSummary which shows information to user as upload
progresses.
I make a call from my main method as follows:
try
{
t.doFTPUpload(client,logs,txtSummary);
}
catch (Exception eUpload)
{
logs.addToLog("Upload Failed!");
logs.addToLog(eUpload.ToString());
}
Now how can I modify this code to start a new worker thread and make
the call to doFTPUpload inside this thread. Also how can I put a
timeout on it so that if the thread doesn't finish up in say 60
seconds, I manually kill the thread and go on with my execution inside
the main method?
Thanks.
Asad