From 10f307be233cae81865998f666fc6d2df4a0c298 Mon Sep 17 00:00:00 2001 From: Ezio Date: Tue, 2 May 2023 13:26:38 -0400 Subject: [PATCH 1/2] Assert dispose on close window --- NWNLogRotator.xaml.cs | 3 +++ Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NWNLogRotator.xaml.cs b/NWNLogRotator.xaml.cs index cbfd2bf..8df1380 100644 --- a/NWNLogRotator.xaml.cs +++ b/NWNLogRotator.xaml.cs @@ -722,6 +722,9 @@ protected override void OnStateChanged(EventArgs e) private void WindowClosed_Event(object sender, CancelEventArgs e) { ni.Visible = false; + ni.Icon = null; + ni.Dispose(); + System.Windows.Forms.Application.DoEvents(); } /* diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 3955232..cb8091b 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0.1")] -[assembly: AssemblyFileVersion("0.1.0.1")] +[assembly: AssemblyVersion("0.1.0.2")] +[assembly: AssemblyFileVersion("0.1.0.2")] From 5e37e15630817b92612420bb0e4b58d8648d94a4 Mon Sep 17 00:00:00 2001 From: Ezio Date: Tue, 2 May 2023 16:01:02 -0400 Subject: [PATCH 2/2] Attempt #2 --- App.xaml | 3 ++- App.xaml.cs | 7 ++++++- NWNLogRotator.xaml.cs | 28 ++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/App.xaml b/App.xaml index e3c3f51..be41e02 100644 --- a/App.xaml +++ b/App.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:NWNLogRotator" - StartupUri="NWNLogRotator.xaml"> + StartupUri="NWNLogRotator.xaml" + Exit="DisposeNotifyIcon"> diff --git a/App.xaml.cs b/App.xaml.cs index 72ca76c..60fc442 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using NWNLogRotator.Classes; +using System.Windows; namespace NWNLogRotator { @@ -7,5 +8,9 @@ namespace NWNLogRotator /// public partial class App : Application { + public void DisposeNotifyIcon(object sender, ExitEventArgs e) + { + NWNLogRotator.MainWindow.ExitEvent(); + } } } \ No newline at end of file diff --git a/NWNLogRotator.xaml.cs b/NWNLogRotator.xaml.cs index 8df1380..d14c4a9 100644 --- a/NWNLogRotator.xaml.cs +++ b/NWNLogRotator.xaml.cs @@ -27,7 +27,7 @@ public partial class MainWindow : Window { FileHandler FileHandlerInstance = new FileHandler(); Settings _settings; - System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); + static System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); Notification notification = new Notification(); private int ClientLauncherState = 0; private string ProcessName = "nwmain"; @@ -37,6 +37,7 @@ public MainWindow() if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1) { MessageBox.Show("There is already an instance of NWNLogRotator running!"); + ExitEvent(); Process.GetCurrentProcess().Kill(); } InitializeComponent(); @@ -244,7 +245,10 @@ private async void IterateNWN_Watcher(bool PreviousStatus) else { if(_settings.CloseOnLogGenerated == true ) + { + ExitEvent(); Process.GetCurrentProcess().Kill(); + } } } @@ -489,8 +493,11 @@ private bool NWNLog_Save(Settings _settings, bool _automatic) } if (_settings.SaveOnLaunch == false) - if (_automatic && _settings.CloseOnLogGenerated == true) Process.GetCurrentProcess().Kill(); - + if (_automatic && _settings.CloseOnLogGenerated == true) + { + ExitEvent(); + Process.GetCurrentProcess().Kill(); + } if (_settings.Silent == false) { MessageBoxResult _messageBoxResult = MessageBox.Show("The log file has been generated successfully. Would you like to open the log file now?", @@ -510,8 +517,12 @@ private bool NWNLog_Save(Settings _settings, bool _automatic) } else { - if(_settings.SaveOnLaunch == false) - if (_automatic && _settings.CloseOnLogGenerated == true) Process.GetCurrentProcess().Kill(); + if (_settings.SaveOnLaunch == false) + if (_automatic && _settings.CloseOnLogGenerated == true) + { + ExitEvent(); + Process.GetCurrentProcess().Kill(); + } } return false; @@ -719,7 +730,12 @@ protected override void OnStateChanged(EventArgs e) base.OnStateChanged(e); } - private void WindowClosed_Event(object sender, CancelEventArgs e) + public void WindowClosed_Event(object sender, CancelEventArgs e) + { + ExitEvent(); + } + + public static void ExitEvent() { ni.Visible = false; ni.Icon = null;