English 中文(简体)
为什么在《刑法》中不出现自治。
原标题:Why no AutoResetEventSlim in BCL?

为什么没有这样的编号? AutoResetEventSlim category in BCL?

能否使用<代码>ManualResetEventSlim加以模拟?

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 两者都是为了在发出呼吁后保持信号。 通常的情况与<代码>不同。 AutoResetEvent。

AutoResetEvent在使用后立即返回未签字国,通常用于不同的假设情景。 From AutoReset 活动文件:

通常,当表面需要完全获得资源时,你使用这一类别。

<代码>ManualResetEvent(和Slim)通常用于下列情况:

this communication concerns a task which one thread must complete before other threads can proceed.

由于<代码>AutoResetEvent最常用的假设情景是,在资源共享方面有多个线索,等候时间通常不会太短。 但是,只有当你事先知道等候时间非常短时,才真正打算使用“ManualResetEventSlim。 如果您的等待时间不会太短,那么你就应当使用<代码>ManualResetEvent。 See the documentation on the difference between MRE and MRES for details.

当您的等待时间较长时(这将是的正常情况),“气候”一词实际上就更糟,因为它再次使用等待处理。

问题回答

I was bugged by this fact as well. However, it appears that you can simulate an AutoResetEvent(Slim) using a simple SemaphoreSlim with a special configuration:

SemaphoreSlim Lock = new SemaphoreSlim( 1, 1 );

In the constructor, the first parameter defines the initial state of the semaphore: 1 means that one thread may enter, 0 that the semaphore has to be released first. So new AutoResetEvent( true ) translates to new SemaphoreSlim( 1, 1 ) and new AutoResetEvent( false ) translates to new SemaphoreSlim( 0, 1 ) respectively.

第二项参数界定了可能同时进入ema体的深层的最大数量。 编号为1 请将其作为<条码>行事。 AutoResetEvent。

One other nice thing about the SemaphoreSlim is that with the new async/await pattern in 4.5 the class has received a .WaitAsync() method which can be awaited. So there is no need to manually create an awaitable wait primitive in this case any more.

Hope this helps.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签