views:

307

answers:

2

Unfortunately, there is no Semaphore in System.Threading when using the .NET Compact Framework. I'm not sure why that is, does anyone have an idea?

After googling I've found a bunch of people giving their own implementations, but none of them really worked great... or at all!

So I've come to ask the experts...

Does anyone have a good semaphore class/library they can recommend for the .NET compact framework?

OR

Is there someway I can emulate the behaviour?

I have a typical producer/consumer setup in which a thread pushes objects on to a Queue (System.Collections). I then want a consumer thread to pull objects off the queue and do work, but obviously only when there are things on the queue to work with!

I am working in C#, but I'll take solutions/pseudo in any language so long as I can implement it on .NET CF.

+4  A: 

You can just PInvoke to CreateSemaphore and ReleaseSemaphore- they're implemented on CE in coredll. Pretty easy to write a nice managed wrapper that looks like System.Threading.Semaphore.

nitzmahone
I was wondering if that's the best way. Thanks for your response
Fuzz
+2  A: 

I think there is a semaphore implementation in OpenNETCF

Quibblesome
so there is.... :-)I'm still at a loss as to why it hasn't been includedSure there was lots missing from .NET CF 1.0, but we're up to 3.5 and still no semaphore. Semaphore's are a fairly core inter-process communications device.
Fuzz
TELL ME ABOUT IT. M$ obviously don't care about CF or are planning to replace WinCE/CF with something else. That is the only reasoning I can come up with. The package size argument is silly as devices have more space these days and they could always have a "fuller" version or release these kind of libraries as add ons.
Quibblesome
I agree. CF has been sorely neglected. OpenNETCF is the BEST.
0A0D