I have some thread in some page (e.g page1) in wp7. I want to close these thread when the application deactivated in this page, not in the global application file.When application deactivated from some other page only this page onNvavigateFrom is called, bit page1 onNavigateFrom isn’t called. How can I do that? Or what is the best practice to close such threads?
Share
If your thread is the result of using
BackgroundWorker(the recommended approach), you should be periodically checkingCancellationPendingas described on theDoWorkdocumentation.If you are creating your own Thread, you can emulate this behavior by setting a boolean flag that is checked periodically (in a loop or whatever) by your thread. What you shouldn’t do is call Thread.Abort as that could leave you with corrupted state if you write to the isolated storage or a database.