A
Asad Khan
I call the following method from my main form method:
uploadThread = new Thread(new ThreadStart
(this.doFTPUpload));
uploadThread.Name = "FTP Upload";
uploadThread.Start();
bool threadTerminatedGood =
uploadThread.Join(client.transmissionTimeout*60*1000);
if (!threadTerminatedGood) {
throw new Exception("The upload thread was interrupted by main thread
because it timed out");
}
// some more code
This works great and does what its supposed to do. However, it hangs my
GUI until the thread exits (either by itself or by exceeding the
allocated timeout). What I want to do is for it to start the thread and
wait for the thread to finish or timeout. While its running or timing
out, if the user clicks a stop button, the thread should get killed
immediately. However, this is not possible, as the GUI just becomes
non-interactive (I presume because it goes into a sleep mode because of
the join call) while the thread runs or times out.
So how can I run the thread, wait for it to finish or timeout, and
meanwhile still be able to respond to user events such as button clicks
etc. (that is keep my GUI from going non-interactive).
Thanks.
Asad
uploadThread = new Thread(new ThreadStart
(this.doFTPUpload));
uploadThread.Name = "FTP Upload";
uploadThread.Start();
bool threadTerminatedGood =
uploadThread.Join(client.transmissionTimeout*60*1000);
if (!threadTerminatedGood) {
throw new Exception("The upload thread was interrupted by main thread
because it timed out");
}
// some more code
This works great and does what its supposed to do. However, it hangs my
GUI until the thread exits (either by itself or by exceeding the
allocated timeout). What I want to do is for it to start the thread and
wait for the thread to finish or timeout. While its running or timing
out, if the user clicks a stop button, the thread should get killed
immediately. However, this is not possible, as the GUI just becomes
non-interactive (I presume because it goes into a sleep mode because of
the join call) while the thread runs or times out.
So how can I run the thread, wait for it to finish or timeout, and
meanwhile still be able to respond to user events such as button clicks
etc. (that is keep my GUI from going non-interactive).
Thanks.
Asad