If I am using EventWaitHandle
(or AutoResetEvent
, ManualResetEvent
) to synchronise between threads then do I need to call the Cl
The disposable resource of an EventWaitHandle
is actually a SafeHandle
(wrapped in a SafeWaitHandle
). SafeHandle
implements a finalizer, which eventually makes sure the necessary resource is release, so it should be safe to let the garbage collector / finalizer thread handle it in this case.
However, it is always a good idea to explicitly call Dispose()
when the resource is no longer needed.
The threading chapter in C# 3.0 in a Nutshell states
This practice is (arguably) acceptable with wait handles because they have a light OS burden (asynchronous delegates rely on exactly this mechanism to release their
IAsyncResult
's wait handle).