帮助移植线程功能:Win32 --> 。网
我负责将一个类从旧版 Win32 代码移植到 .Net,并且我遇到了一个线程模型,我不确定如何最好地在 .Net 中实现该模型。基本上,Win32 有一个工作线程,它调用 WaitForMultipleObjects() 并在触发特定对象时执行特定的代码段。这具有一种先到先服务的效果,我需要在自己的代码中模拟这种效果。但我不确定如何在 .Net 中最好地做到这一点。有人知道吗?
我发现.Net 中没有相当于 WaitForMultipleObjects() 的类,只有 ThreadPool 类,它似乎提供了我需要的大部分内容,但我不确定它是否是最好的,因为我总共只有四个对象需要等待并执行代码。
谢谢,丹尼尔
I am responsible for porting a class from legacy Win32 code to .Net and I have come across a threading model that I'm not sure how best to implement in .Net. Basically the Win32 has one worker thread, which calls WaitForMultipleObjects() and executes the particular piece of code when a particular object has been triggered. This has a sort of first-come-first-serve effect that I need to emulate in my own code. But I'm not sure how best to do this in .Net. Does anyone have any idea?
I see that there is no equivalent of WaitForMultipleObjects() in .Net, only the ThreadPool class, which seems to provide most of what I need, but I'm not sure if it's the best, since I only have four objects total to wait and execute code for.
Thanks, Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么,有
WaitHandle.WaitAny
和WaitHandle.WaitAll
- 这对您有帮助吗?诚然,我可能不会一开始就使用这种方法:我会使用生产者/消费者队列。您使用的是.NET 4吗?它通过并行扩展提供了更好的线程支持,这使得这种事情变得简单。
Well, there are
WaitHandle.WaitAny
andWaitHandle.WaitAll
- does that help you?Admittedly, I probably wouldn't use that approach to start with: I would use a producer/consumer queue. Are you using .NET 4? That has much better threading support via Parallel Extensions, which makes this kind of thing easy.