Skip to content

Commit 8da165d

Browse files
committed
fix(Program): Crash when stopping the application
Fixes SOUNDSWITCH-1
1 parent 3e2fe17 commit 8da165d

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

SoundSwitch/Model/AppModel.cs

+7
Original file line numberDiff line numberDiff line change
@@ -480,5 +480,12 @@ public NoDevicesException() : base("No devices to select")
480480
}
481481

482482
#endregion
483+
484+
public void Dispose()
485+
{
486+
TrayIcon?.Dispose();
487+
ActiveAudioDeviceLister?.Dispose();
488+
ActiveUnpluggedAudioLister?.Dispose();
489+
}
483490
}
484491
}

SoundSwitch/Model/IAppModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace SoundSwitch.Model
2929
{
30-
public interface IAppModel
30+
public interface IAppModel : IDisposable
3131
{
3232
#region Properties
3333

SoundSwitch/Program.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@ private static void Main()
129129
HandleException(ex);
130130
}
131131
#endif
132-
AppModel.Instance.ActiveAudioDeviceLister.Dispose();
133-
AppModel.Instance.ActiveUnpluggedAudioLister.Dispose();
134-
AppModel.Instance.TrayIcon.Dispose();
132+
AppModel.Instance.Dispose();
135133
WindowsAPIAdapter.Stop();
136-
MMNotificationClient.Instance.Dispose();
134+
MMNotificationClient.Instance?.Dispose();
137135
Log.CloseAndFlush();
138136
}
139137

0 commit comments

Comments
 (0)