Guest pai Posted May 11, 2005 Report Posted May 11, 2005 Hello, again i have wrote an application, which has a Thread (there is a for(;;) in it ). So when I want to close the application, I must, in the first, close this Thread, then the application can be stopped, and everything are fine. But the problem is, if i close the application with tast manager, the application can be stopped, but the Thread runs continue, has anyone an idea, how to stop the Thread, too , with Tast Manager, what should I put in the code? Thanks again.
Guest mossywell Posted May 13, 2005 Report Posted May 13, 2005 But the problem is, if i close the application with tast manager, the application can be stopped, but the Thread runs continue, <{POST_SNAPBACK}> Indeed that is what happens in the CF. You've also discovered that there's no Abort method in the CF (some say Abort shouldn't exist in the full .net framework)? Here's one way to solve it... create a flag of some kind to notify the worker thread that it is to shutdown and then loop based on the flag. E.g., while(!m_threadhasbeenaskedtoshutdown) { do stuff; sleep(5000); } Set m_threadhasbeenaskedtoshutdown to false before starting the worker thread. Then, to ensure that the thread closes when forced to via Task Manager, set the flag to true in the UI's Closing event. Cheep and cheerful, but it does work. You might want to tidy it up a bit to ensure that the UI only closes once the worker has stopped. This takes a tiny bit more work, but in production code, it's generally a good idea to ensure that once the UI (and hence the user) thinks the app is dead, it really is dead. 8) HTH
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now