Help with porting thread functionality: Win32 --> .Net
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 equiv开发者_如何学编程alent 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
Well, there are WaitHandle.WaitAny
and WaitHandle.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.
精彩评论