简体   繁体   中英

Semaphores in .NET compact framework

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.

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.

我认为OpenNETCF中有一个信号量实现

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM