views:

24

answers:

1

Hi, 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

+1  A: 

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.

Jon Skeet
Thanks John, the WaitHandle just about does it. My initial thought was to implement a queue to process, as you suggested, so I may go ahead with that. Good to know about the Parallel Extensions.
JimDaniel