Rule 3: For a class owning a single unmanaged resource, implement both IDisposable and a finalizer

A class that owns a single unmanaged resource should not be responsible for anything else. It should only be responsible for closing that resource.

No class should be responsible for multiple unmanaged resources.

No class should be responsible for both managed and unmanaged resources.

This implementation of IDisposable should call an internal “CloseHandle” method and then end with a call to GC.SuppressFinalize(this).

The internal “CloseHandle” method should close the handle if it is a valid value, and then set the handle to an invalid value. This makes “CloseHandle” (and therefore Dispose) safe to call multiple times.