You've already forked Sonarr
							
							
				mirror of
				https://github.com/Sonarr/Sonarr.git
				synced 2025-10-31 00:07:55 +02:00 
			
		
		
		
	Dispose tray icon when application is exited
This commit is contained in:
		| @@ -1,6 +1,8 @@ | ||||
| using System; | ||||
| using System.ComponentModel; | ||||
| using System.Drawing; | ||||
| using System.Reflection; | ||||
| using System.Threading; | ||||
| using System.Windows.Forms; | ||||
| using NzbDrone.Common; | ||||
| using NzbDrone.Common.EnvironmentInfo; | ||||
| @@ -30,6 +32,9 @@ namespace NzbDrone.SysTray | ||||
|  | ||||
|         public void Start() | ||||
|         { | ||||
|             Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException); | ||||
|             Application.ApplicationExit += new EventHandler(OnApplicationExit); | ||||
|  | ||||
|             _trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser); | ||||
|             _trayMenu.MenuItems.Add("-"); | ||||
|             _trayMenu.MenuItems.Add("Exit", OnExit); | ||||
| @@ -44,6 +49,11 @@ namespace NzbDrone.SysTray | ||||
|             Application.Run(this); | ||||
|         } | ||||
|  | ||||
|         protected override void OnClosing(CancelEventArgs e) | ||||
|         { | ||||
|             DisposeTrayIcon(); | ||||
|         } | ||||
|  | ||||
|         protected override void OnClosed(EventArgs e) | ||||
|         { | ||||
|             Console.WriteLine("Closing"); | ||||
| @@ -77,5 +87,23 @@ namespace NzbDrone.SysTray | ||||
|         { | ||||
|             _processProvider.Start(_hostController.AppUrl); | ||||
|         } | ||||
|  | ||||
|         private void OnApplicationExit(object sender, EventArgs e) | ||||
|         { | ||||
|             DisposeTrayIcon(); | ||||
|         } | ||||
|  | ||||
|         private void OnThreadException(object sender, EventArgs e) | ||||
|         { | ||||
|             DisposeTrayIcon(); | ||||
|         } | ||||
|  | ||||
|         private void DisposeTrayIcon() | ||||
|         { | ||||
|             _trayIcon.Visible = false; | ||||
|             _trayIcon.Icon = null; | ||||
|             _trayIcon.Visible = false; | ||||
|             _trayIcon.Dispose(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user