简体   繁体   English

在Silverlight中,将导航远离包含线程的页面结束线程吗?

[英]In Silverlight, will navigating away from the page that contains a thread end the thread?

I have a Silverlight 3 project. 我有一个Silverlight 3项目。 When one of the pages is loaded, a System.Threading.Thread object is created and started. 加载其中一个页面时,将创建并启动System.Threading.Thread对象。 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? 这会自动发生,还是我必须在OnNavigatingFrom事件中手动终止线程?

Thanks for any help. 谢谢你的帮助。

The Thread object can be destroyed but the process thread it created will continue to run until the method that it originally invoked returns. Thread对象可以被销毁,但它创建的进程线程将继续运行,直到它最初调用的方法返回。

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. 因此,如果你在某个循环中有一些永远不会返回的代码,那么线程将继续,直到你做一些事情来中断该循环,无论你如何处理创建它的Thread对象。 IMO the class Thread is a bit of a mis-nomer. IMO类Thread是一个错误的例子。

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. 退出页面后,计时器将停止执行操作,您将可以更好地控制系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM