简体   繁体   English

AutoResetEvent / ManualResetEvent使用哪些资源?

[英]What resources do AutoResetEvent / ManualResetEvent consume?

Are the c# ManualResetEvent and AutoResetEvent classes expensive to create or to maintain? c# ManualResetEventAutoResetEvent类是否很难创建或维护?

Do they consume some kind of limited Windows kernel resources, and if so, how limited is it? 他们是否消耗某种有限的Windows内核资源,如果是这样,它有多受限制?

Eg if I have code that can create a new AutoResetEvent every 100ms (to be disposed shortly afterwards), should I worry about putting old AutoResetEvents in a pool and reusing them, or is that not a significant concern? 例如,如果我的代码可以每100毫秒创建一个新的AutoResetEvent(之后不久就要处理),我是否应该担心将旧的AutoResetEvents放入池并重用它们,或者这不是一个重要的问题?

Since they are IDisposables, I presume they consume some sort of limited resource. 由于它们是IDisposables,我认为它们消耗某种有限的资源。 Just how much do they consume, and at which point should I start worrying about using too many of them? 它们消耗了多少,在哪一点上我应该开始担心使用太多它们?

The fact that there is a ManualResetEventSlim, but no AutoResetEventSlim also worries me a bit. 事实上有一个ManualResetEventSlim,但没有AutoResetEventSlim也让我有点担心。

ManualResetEvent uses Wait Handles whereas ManualResetEventSlim uses Busy Spinning ManualResetEvent使用Wait Handles,而ManualResetEventSlim使用Busy Spinning

The best performance, in order, is: 1) standard locking (Monitor) 2) "slim" event classes 3) standard event classes 按顺序排列的最佳性能是:1)标准锁定(监视器)2)“苗条”事件类3)标准事件类

Given your use case, I would recommend using the "slim" classes, since you will only be waiting for a short amount of time. 考虑到你的用例,我建议使用“瘦”类,因为你只会等待很短的时间。 Also, if a "slim" class waits for too long, it behaves as a "non-slim" class anyway. 而且,如果一个“苗条”的课程等待太长时间,它无论如何都表现为“非苗条”课程。

Note you cannot use the "slim" classes across processes. 请注意,您不能跨进程使用“苗条”类。


EDIT: This is why AutoResetEvent does not have a "slim" version - basically it's because the wait times of AutoResetEvent are typically longer than ManualResetEvent, so it isn't appropriate to use "busy spinning" 编辑:这就是为什么AutoResetEvent没有“苗条”版本 - 基本上是因为AutoResetEvent的等待时间通常比ManualResetEvent长,所以不适合使用“忙碌的旋转”


EDIT: A wait handle inherits from MarshalByRefObject. 编辑:等待句柄继承自MarshalByRefObject。 Ultimately .NET runtime sets up a proxy (TransparentProxy class) for remote access to your wait handle. 最终,.NET运行时设置了一个代理(TransparentProxy类),用于远程访问等待句柄。

See here and here for more information. 有关更多信息,请参见此处此处


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

相关问题 .NET中的ManualResetEvent和AutoResetEvent有什么区别? - What is the difference between ManualResetEvent and AutoResetEvent in .NET? AutoResetEvent和ManualResetEvent之间的混合 - Hybrid between AutoResetEvent and ManualResetEvent AutoResetEvent.Set()有什么作用? - What does AutoResetEvent.Set() do ? 是否有.Net类来执行ManualResetEvent.PulseAll()(如果存在)会做什么? - Is there a .Net class to do what ManualResetEvent.PulseAll() would do (if it existed)? 如何在C#中检查AutoResetEvent或ManualResetEvent的阻塞状态? - How to check the blocking state of AutoResetEvent or ManualResetEvent in C#? ManualResetEvent在处于等待状态时会消耗cpu吗? - Will the ManualResetEvent consume cpu while it is in a wait state? 这里的ManualResetEvent或ManualResetEventSlim有什么用? - What is the usage of ManualResetEvent or ManualResetEventSlim here? 为什么在C#中使用AutoResetEvent和ManualResetEvent时,我的代码输出为何不同? - Why the outputs of my code is difference when using AutoResetEvent and ManualResetEvent in C# Linux下的AutoResetEvent的C ++等价物是什么? - What is the C++ equivalent for AutoResetEvent under Linux? 我需要在ManualResetEvent上调用Close()吗? - Do I need to call Close() on a ManualResetEvent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM