Semaphores in .NET compact framework

2019-07-07 09:14发布

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.

2条回答
不美不萌又怎样
2楼-- · 2019-07-07 09:43

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.

查看更多
来,给爷笑一个
3楼-- · 2019-07-07 09:47

I think there is a semaphore implementation in OpenNETCF

查看更多
登录 后发表回答