为什么没有这样的编号? AutoResetEventSlim category in BCL?
能否使用<代码>ManualResetEventSlim加以模拟?
为什么没有这样的编号? 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.
引用Microsoft scott Phillips(:
As for AutoResetEventSlim.. is there a scenario for which you need it? Truth be told, creating an AutoResetEvent is quite difficult and the use cases are very limited so we prioritized our efforts elsewhere. If there s a real need for you to have one, I d love to hear it so we could consider creating one!
扩大评论:你只能使用手工活动,确保总是在等待后重新开始。
如果等待和重新确定之间的这种小的拖延造成问题,可能有一些根本问题。 例如,如果存在多个消费者,而且你只能让自己来做,那么,一项活动可能就没有合适的工作工具,你应考虑<代码>。 SemaphoreSlim 或甚至仅限原始<代码>。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
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. ...
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 ...
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 ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
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, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
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. ...