我需要的Dispose()或Close()的的EventWaitHandle? [英] Do I need to Dispose() or Close() an EventWaitHandle?

查看:287
本文介绍了我需要的Dispose()或Close()的的EventWaitHandle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用的EventWaitHandle (或的AutoResetEvent 的ManualResetEvent )在线程之间同步的话,我需要调用关闭()的Dispose()在该方法事件句柄时,我用它我做了什么?

If I am using EventWaitHandle (or AutoResetEvent, ManualResetEvent) to synchronise between threads then do I need to call the Close() or Dispose() methods on that event handle when I am done with it?

的EventWaitHandle 的WaitHandle 继承,它实现的IDisposable 。而FxCop的抱怨,如果我不落实的IDisposable 上包含一个的EventWaitHandle 任何类。因此,这意味着我需要调用它。

EventWaitHandle inherits from WaitHandle, which implements IDisposable. And FxCop complains if I don't implement IDisposable on any class that contains an EventWaitHandle. So this suggests that I do need to call it.

但是没有这些MSDN用法示例调用的Dispose()关闭()

However none of these MSDN usage examples call Dispose() or Close():

<一个href="http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle(VS.80).aspx">http://msdn.microsoft.com/en-us/library/system.threading.eventwaithandle(VS.80).aspx <一href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent(VS.80).aspx">http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent(VS.80).aspx <一href="http://msdn.microsoft.com/en-us/library/system.threading.autoresetevent(VS.80).aspx">http://msdn.microsoft.com/en-us/library/system.threading.autoresetevent(VS.80).aspx

是微软忽略了自己的意见这只是举个例子?

Is this just an example of Microsoft ignoring their own advice?

推荐答案

您需要显式地处理它们。关闭()更适合她们因为它调用Dispose()。

You need to dispose them explicitly. Close() is more appropriate for them as it does call Dispose().

这篇关于我需要的Dispose()或Close()的的EventWaitHandle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆