views:

126

answers:

2

I have a Silverlight 3 project. When one of the pages is loaded, a System.Threading.Thread object is created and started. I want to make sure that it terminates when the user navigates away from the page. Will this happen automatically, or do I have to manually terminate the thread in the OnNavigatingFrom event?

Thanks for any help.

+1  A: 

Nope, A thread will keep on living even if there are no references to it.

Maybe, instead of using a thread (which I can only assume has a repeating operation) you can set a timer that queues that operation to the threadpool. the timer will stop executing the operation once you exit the page and you will have more control over your system.

Gilad
+2  A: 

The Thread object can be destroyed but the process thread it created will continue to run until the method that it originally invoked returns.

So if you have some code in some loop that never returns that thread will continue until you do something to interrupt that loop, regardless of what you do with the Thread object that created it. IMO the class Thread is a bit of a mis-nomer.

AnthonyWJones