[英]What resources do AutoResetEvent / ManualResetEvent consume?
Are the c# ManualResetEvent and AutoResetEvent classes expensive to create or to maintain? c# ManualResetEvent和AutoResetEvent类是否很难创建或维护?
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.