[英]How can I know when a thread ends on .Net Compact Framework?
I'm developing a Windows Mobile 5.0 and above application using .Net Compact Framework 2.0 SP 2 and C# . 我正在使用.Net Compact Framework 2.0 SP 2和C#开发Windows Mobile 5.0及更高版本的应用程序。
How can I know when a thread ends? 我怎么知道线程什么时候结束?
This is my code: 这是我的代码:
System.Threading.Thread thread1 =
new System.Threading.Thread(() => RetreiveSoMuchData(ID));
thread1.Start();
Thank you. 谢谢。
You'll need to get the thread to: 您需要获取该主题:
Unfortunately neither of these leaves the thread alone or doesn't pull in other threads, but this is the joy of multithreading. 不幸的是,这些都没有留下线程或者没有引入其他线程,但这是多线程的乐趣。 I'd generally go for firing an event myself. 我一般都会去自己开一个活动。 The BackgroundWorker object in the Full Framework does this but unfortunately is not available in CF so you'll have to write that yourself (perhaps write a wrapper for the Thread class that does this for you). 完整框架中的BackgroundWorker对象执行此操作但很遗憾在CF中不可用,因此您必须自己编写(也许为Thread类编写一个包装器来为您执行此操作)。
Since you're spawning your own thread, as soon as RetrieveSoMuchData(..) finishes, the thread will terminate. 由于您正在生成自己的线程,所以一旦RetrieveSoMuchData(..)完成,线程就会终止。
You can notify yourself of this by using an EventWaitHandle, such as a AutoResetEvent . 您可以使用EventWaitHandle(例如AutoResetEvent)通知您自己。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.