简体   繁体   English

.NET紧凑框架中的信号量

[英]Semaphores in .NET compact framework

Unfortunately, there is no Semaphore in System.Threading when using the .NET Compact Framework. 不幸的是,在使用.NET Compact Framework时,System.Threading中没有Semaphore。 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? 有没有人有一个很好的信号量类/库,他们可以推荐.NET紧凑框架?

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). 我有一个典型的生产者/消费者设置,其中一个线程将对象推送到队列(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. 我在C#工作,但只要能在.NET CF上实现它,我就会使用任何语言的解决方案/伪。

You can just PInvoke to CreateSemaphore and ReleaseSemaphore- they're implemented on CE in coredll. 你可以只是PInvoke到CreateSemaphore和ReleaseSemaphore-它们是在coredll上的CE上实现的。 Pretty easy to write a nice managed wrapper that looks like System.Threading.Semaphore. 很容易编写一个看起来像System.Threading.Semaphore的好的托管包装器。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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