Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Service/NotificationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
Expand Down Expand Up @@ -479,8 +479,8 @@ public void Loading(bool running)
if (WpfApplication.Current == null || WpfApplication.Current.Dispatcher == null)
return;

// Multi-threading trick
WpfApplication.Current.Dispatcher.Invoke((Action)delegate
// Multi-threading safe dispatch
WpfApplication.Current.Dispatcher.BeginInvoke((Action)delegate
{
Mouse.OverrideCursor = running ? Cursors.Wait : null;

Expand Down Expand Up @@ -572,7 +572,7 @@ private void StartRotationAnimation()

try
{
WpfApplication.Current.Dispatcher.Invoke((Action)delegate
WpfApplication.Current.Dispatcher.BeginInvoke((Action)delegate
{
try
{
Expand Down Expand Up @@ -610,7 +610,7 @@ private void StopRotationAnimation()
return;
}

WpfApplication.Current.Dispatcher.Invoke((Action)delegate
WpfApplication.Current.Dispatcher.BeginInvoke((Action)delegate
{
CleanupRotationTimer();
});
Expand Down
23 changes: 13 additions & 10 deletions src/View/Window/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
Expand Down Expand Up @@ -213,21 +213,25 @@ private void OnOptimizeCommandCompleted()
}
else
{
Thread.Sleep(1000);
App.Shutdown();
var timer = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
timer.Tick += (sender, args) =>
{
timer.Stop();
App.Shutdown();
};
timer.Start();
}
}
else
{
_viewModel.IsBusy = false;

// Wait for the button to be enabled before trying to refocus it
// The button is disabled while IsOptimizationRunning = true
// Wait for the button to be enabled before trying to refocus it
Dispatcher.BeginInvoke(new Action(() =>
{
SetFocusTo(Optimize, force: true);
}), System.Windows.Threading.DispatcherPriority.Loaded);
}
{
SetFocusTo(Optimize, force: true);
}), System.Windows.Threading.DispatcherPriority.Loaded);
}
}

/// <summary>
Expand Down Expand Up @@ -348,7 +352,6 @@ private void SetFocusTo(object element, bool force = false)
else
{
// Normal focus - immediate
Keyboard.ClearFocus();
Keyboard.Focus(uiElement);
FocusManager.SetFocusedElement(this, inputElement);
}
Expand Down
7 changes: 6 additions & 1 deletion src/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -1706,7 +1706,12 @@ private void MonitorComputer()
{
// Check if it's busy
if (IsBusy)
{
if (_cancellationTokenSource.Token.WaitHandle.WaitOne(1000))
break;

continue;
}

lock (_lockObject)
{
Expand Down
Loading