/// <summary> /// Disposes this instance. /// </summary> public void Dispose() { // ReSharper disable ExceptionNotDocumented FileSystemWatcher watcher = Interlocked.Exchange(ref _watcher, null); watcher?.Dispose(); BufferedAction action = Interlocked.Exchange(ref _eventAction, null); action?.Dispose(); // ReSharper restore ExceptionNotDocumented }
/// <summary> /// Disposes the specified instance. /// </summary> /// <param name="disposing">Whether this is disposing or finalizing.</param> /// <remarks> /// <para><paramref name="disposing"/> indicates whether the method was invoked from the /// <see cref="IDisposable.Dispose"/> implementation or from the finalizer. The implementation should check the /// parameter before accessing other reference objects. Such objects should only be accessed when the method /// is called from the <see cref="IDisposable.Dispose"/> implementation (when the <paramref name="disposing"/> /// parameter is equal to <see langword="true"/>). If the method is invoked from the finalizer /// (disposing is false), other objects should not be accessed. The reason is that objects are finalized in an /// unpredictable order and so they, or any of their dependencies, might already have been finalized.</para> /// </remarks> // ReSharper disable once VirtualMemberNeverOverriden.Global protected virtual void Dispose(bool disposing) { IsDisposed = true; // ReSharper disable once ExceptionNotDocumented // If we're disposing the active configuration section, we want to reload the active configuration. Interlocked.CompareExchange(ref _active, null, (T)this); if (!disposing) { return; } ConfigurationFileWatcher.UnWatch(this); // ReSharper disable once ExceptionNotDocumented BufferedAction <string> action = Interlocked.Exchange(ref _changeAction, null); action?.Dispose(); }