BrightnessTray.EventWatcherAsync.Dispose C# (CSharp) Method

Dispose() public method

public Dispose ( ) : void
return void
        public void Dispose()
        {
            if (Watcher != null)
            {
                Watcher.Stop();
            }

            Watcher.Dispose();
        }

Usage Example

        /// <summary>
        /// Window closing method. Disposes of the notify icon, removes the custom window procedure and releases user preference change handlers.
        /// </summary>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="e">Cancel event arguments.</param>
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            eventWatcher.Dispose();

            // remove the notify icon
            this.NotifyIcon.Visible = false;
            this.NotifyIcon.Dispose();

            if (this.IsLoaded)
            {
                HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
                source.RemoveHook(this.WndProc);
            }

            this.ReleaseHandlers();
        }