// The bulk of the clean-up code is implemented in Dispose(bool) protected virtual void Dispose(bool disposing) { if (_isDisposed) { return; } if (disposing) { // free managed resources // Managed resources are those that are pure .NET code and managed by the runtime and are under its direct control. DirectoryInfo = null; if (Watcher != null) { Watcher?.EndInit(); Watcher?.Dispose(); } } //// free native resources if there are any. //if (nativeResource != IntPtr.Zero) //{ // // Unmanaged resources are those that are not. File handles, pinned memory, COM objects, database connections etc // Marshal.FreeHGlobal(nativeResource); // nativeResource = IntPtr.Zero; //} _isDisposed = true; }