[RESOLVED] Canceling async calls
Hi,
I'm using the MethodInvoker to set a background process to work.
That process can take quite an amount of time, so I want the user to be able to cancel that.
Now my worries are that if I use Application.Exit() it doesn't quit or that the thread is not cleaned up correctly.
Any thoughts on this?
Thanks.
Re: Canceling async calls
If you set the IsBackground property of a Thread to True before you Start it, it will not prevent the application closing. If that's not enough information then you're going to have to provide us with more information, i.e. exactly what you're doing, including code.
Re: Canceling async calls
Ignore my comment.
I seem to have mixed up the use of a background process with the use of the BackgroundWorker process.
Appologies for the missinterpetation.
Re: Canceling async calls
Application.Exit() is the same as calling Abort() on a thread, so if you've got proper cleanup, you're fine (back - but Application.Exit() will throw a security exception on some restricted accounts (it did on my school computers) so you should just set IsBackground. Environment.Exit() is different, though...
Re: Canceling async calls
Environment.Exit returns a number back to the process/OS.
It terminates the process with a number. IT also throws a Security Exception, depending on the account you are using and security setting configurations on the account or for applications and generally is used for console based apps (but not restricted to them)
The thread in question can continue to run unless you set the IsBackground property to true on the Thread object, as highlighted earlier on.
http://msdn.microsoft.com/en-us/libr...ackground.aspx for more information.
Re: Canceling async calls
Environment.Exit() also completely terminates every thread without raising the ThreadAbortException.
Re: Canceling async calls
it is advisable to use the correct approach to exit your application rather than just "stabbing in the dark until you get it" :)
Re: Canceling async calls
Well, he's already got it.