简体   繁体   English

我怎么知道线程何时结束.Net Compact Framework?

[英]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: 您需要获取该主题:

  • Fire an event that someone is listening to 发起某人正在听的事件
  • Set a value someone else is checking 设置其他人正在检查的值
  • Set a wait event that another thread is waiting on (eg a AutoResetEvent or ManualResetEvent) 设置另一个线程正在等待的等待事件(例如,AutoResetEvent或ManualResetEvent)
  • Return on an infinite join() command (on that thread) 返回无限join()命令(在该线程上)

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.

相关问题 Compact Framework 2.0:处置对象时如何停止线程? - Compact Framework 2.0: How can I stop a thread when an object is dispose? 我如何确定紧凑框架具有哪些.Net功能? - How can i determine which .Net features the compact framework has? 如何使用.NET Compact Framework安全地隐藏文件? - How can I securely hide a file using the .NET Compact Framework? 您可以访问.net Compact Framework中的线程状态吗? - Can you access Thread State in .net Compact Framework? 如何知道在.Net Compact Framework WinForms应用程序中加载了控件? - How to know that a control is loaded in .Net Compact Framework, WinForms application? 事件是否在另一个线程中运行? (.Net Compact Framework) - Is an Event running in another thread? (.Net Compact Framework) 我怎么可以转换使用StandardInput和StandardOutput在.NET Compact Framework的C#应用​​程序? - How can I convert a C# application that uses StandardInput and StandardOutput in .NET Compact Framework? 如何在Compact Framework的.NET 1.1中将枚举值分配给列表框? - How can I assign enum values to a listbox in .NET 1.1 on the Compact Framework? 如何使用 C# .Net Compact Framework 打开图像并编辑图像。 - How can I open an image and edit the image with C# .Net Compact Framework. 如何在.NET Compact Framework应用程序中嵌入广告? - How do I embed ads in .NET Compact Framework application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM