The developers of the .NET base class library decided to implement the Dispose method using an explicit interface implementation :
private void IDisposable.Dispose() { ... }
The Dispose method is private, and the only way to call it is to pass an IDisposable as you discovered.
The reason for this is to configure the Dispose method name to better describe how the object is located. For ManualResetEvent custom method is the Close method.
To get rid of ManualResetEvent , you have two good options. Using IDisposable :
using (var myManualResetEvent = new ManualResetEvent(false)) { ...
or call Close :
var myManualResetEvent = new ManualResetEvent(false); ...
For more information, see Configuring the name of the deletion method in the Design Guide Implementing Finalize and Dispose to Clean Up Unmanaged Resources on MSDN
Sometimes a domain name is more suitable than Dispose . For example, encapsulating a file may require the use of the Close method name. In this case, execute Dispose privately and create a public Close method that calls Dispose .
Martin liversage
source share