Skip to content

Commit

Permalink
fix shutdown behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomseeen committed May 25, 2022
1 parent 358c333 commit 10c874a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Thomsen.SoundProfiler2/Mvvm/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public void Show() {
}

public bool? ShowDialog() {
if (_view is null) {
_view = new T {
DataContext = this
};
if (_view is not null) {
throw new InvalidOperationException("ShowDialog can only be called once.");
}

_view = new T {
DataContext = this
};

_view.Loaded += View_Loaded;

return _view.ShowDialog();
Expand Down
4 changes: 2 additions & 2 deletions src/Thomsen.SoundProfiler2/VersionAutoIncrement.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ using System.Reflection;

<#+

int major = 0;
int minor = 5;
int major = 1;
int minor = 0;

static DateTime projectStartedDate = new DateTime(year: 2021, month: 8, day: 27);

Expand Down
13 changes: 12 additions & 1 deletion src/Thomsen.SoundProfiler2/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
Expand All @@ -29,7 +30,8 @@ public class MainViewModel : BaseViewModel<MainView> {

#region Private Fields
private bool _disposed = false;
private readonly Timer _refreshTimer = new(500);
private bool _shutingDown = false;
private readonly System.Timers.Timer _refreshTimer = new(500);

private readonly object _mixerApplicationsLock = new();
private readonly object _mappingsLock = new();
Expand Down Expand Up @@ -185,6 +187,12 @@ private async void RefreshAsync() {
await Task.Run(() => {
/* Lock so multiple firing events don't overwrite each other, causing duplicate entries */
lock (_mixerApplicationsLock) {
/* Don't do anything if we are shutting down */
if (_shutingDown) {
return;
}
/* Filter apps by hidden mapping */
MixerApplicationModel[] newApps = FilterMixerApps(CoreAudioHandler.GetMixerApplications());
Expand Down Expand Up @@ -449,6 +457,9 @@ private void MixerApplication_PropertyChanged(object? sender, PropertyChangedEve

#region BaseViewModel
protected override void Dispose(bool disposing) {
_shutingDown = true;
Thread.Sleep(100);

if (!_disposed) {
if (disposing) {
_refreshTimer.Stop();
Expand Down

0 comments on commit 10c874a

Please sign in to comment.