Skip to content

Commit be55d19

Browse files
author
Netrunner
authored
Merge pull request #16 from xNetrunner/TrayFix
Assert dispose on close window
2 parents 18cefdb + 5e37e15 commit be55d19

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

App.xaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:NWNLogRotator"
5-
StartupUri="NWNLogRotator.xaml">
5+
StartupUri="NWNLogRotator.xaml"
6+
Exit="DisposeNotifyIcon">
67
<Application.Resources></Application.Resources>
78
</Application>

App.xaml.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using NWNLogRotator.Classes;
2+
using System.Windows;
23

34
namespace NWNLogRotator
45
{
@@ -7,5 +8,9 @@ namespace NWNLogRotator
78
/// </summary>
89
public partial class App : Application
910
{
11+
public void DisposeNotifyIcon(object sender, ExitEventArgs e)
12+
{
13+
NWNLogRotator.MainWindow.ExitEvent();
14+
}
1015
}
1116
}

NWNLogRotator.xaml.cs

+25-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class MainWindow : Window
2727
{
2828
FileHandler FileHandlerInstance = new FileHandler();
2929
Settings _settings;
30-
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
30+
static System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
3131
Notification notification = new Notification();
3232
private int ClientLauncherState = 0;
3333
private string ProcessName = "nwmain";
@@ -37,6 +37,7 @@ public MainWindow()
3737
if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1)
3838
{
3939
MessageBox.Show("There is already an instance of NWNLogRotator running!");
40+
ExitEvent();
4041
Process.GetCurrentProcess().Kill();
4142
}
4243
InitializeComponent();
@@ -244,7 +245,10 @@ private async void IterateNWN_Watcher(bool PreviousStatus)
244245
else
245246
{
246247
if(_settings.CloseOnLogGenerated == true )
248+
{
249+
ExitEvent();
247250
Process.GetCurrentProcess().Kill();
251+
}
248252
}
249253

250254
}
@@ -489,8 +493,11 @@ private bool NWNLog_Save(Settings _settings, bool _automatic)
489493
}
490494

491495
if (_settings.SaveOnLaunch == false)
492-
if (_automatic && _settings.CloseOnLogGenerated == true) Process.GetCurrentProcess().Kill();
493-
496+
if (_automatic && _settings.CloseOnLogGenerated == true)
497+
{
498+
ExitEvent();
499+
Process.GetCurrentProcess().Kill();
500+
}
494501
if (_settings.Silent == false)
495502
{
496503
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)
510517
}
511518
else
512519
{
513-
if(_settings.SaveOnLaunch == false)
514-
if (_automatic && _settings.CloseOnLogGenerated == true) Process.GetCurrentProcess().Kill();
520+
if (_settings.SaveOnLaunch == false)
521+
if (_automatic && _settings.CloseOnLogGenerated == true)
522+
{
523+
ExitEvent();
524+
Process.GetCurrentProcess().Kill();
525+
}
515526
}
516527

517528
return false;
@@ -719,9 +730,17 @@ protected override void OnStateChanged(EventArgs e)
719730
base.OnStateChanged(e);
720731
}
721732

722-
private void WindowClosed_Event(object sender, CancelEventArgs e)
733+
public void WindowClosed_Event(object sender, CancelEventArgs e)
734+
{
735+
ExitEvent();
736+
}
737+
738+
public static void ExitEvent()
723739
{
724740
ni.Visible = false;
741+
ni.Icon = null;
742+
ni.Dispose();
743+
System.Windows.Forms.Application.DoEvents();
725744
}
726745

727746
/*

Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
// You can specify all the values or you can default the Build and Revision Numbers
5050
// by using the '*' as shown below:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("0.1.0.1")]
53-
[assembly: AssemblyFileVersion("0.1.0.1")]
52+
[assembly: AssemblyVersion("0.1.0.2")]
53+
[assembly: AssemblyFileVersion("0.1.0.2")]

0 commit comments

Comments
 (0)