Semaphores in .NET compact framework

℡╲_俬逩灬. 提交于 2019-12-12 16:15:19

问题


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.


回答1:


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.




回答2:


I think there is a semaphore implementation in OpenNETCF



来源:https://stackoverflow.com/questions/1746923/semaphores-in-net-compact-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!