Skip to content

Commit 1d6d4e7

Browse files
committed
make RefreshWindowsCommand async
1 parent 9e9fd7d commit 1d6d4e7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

WinSyncScroll/ViewModels/MainViewModel.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.ObjectModel;
22
using System.ComponentModel;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Drawing;
54
using System.Runtime.InteropServices;
65
using System.Threading.Channels;
@@ -37,7 +36,7 @@ public sealed partial class MainViewModel : IDisposable
3736
// ReSharper disable once MemberCanBePrivate.Global
3837
public ICollectionView WindowsOrdered { get; }
3938

40-
public RelayCommand RefreshWindowsCommand { get; }
39+
public AsyncRelayCommand RefreshWindowsCommand { get; }
4140
public RelayCommand StartCommand { get; }
4241
public RelayCommand StopCommand { get; }
4342

@@ -94,7 +93,7 @@ public MainViewModel(
9493
_winApiService = winApiService;
9594
_mouseHook = mouseHook;
9695

97-
RefreshWindowsCommand = new RelayCommand(RefreshWindows);
96+
RefreshWindowsCommand = new AsyncRelayCommand(RefreshWindowsAsync);
9897
StartCommand = new RelayCommand(Start);
9998
StopCommand = new RelayCommand(Stop);
10099

@@ -352,11 +351,11 @@ private async Task RunUpdateMouseHookRectsLoopAsync(CancellationToken token)
352351
}
353352
}
354353

355-
private void RefreshWindows()
354+
private async Task RefreshWindowsAsync()
356355
{
357356
_logger.LogInformation("Refreshing windows");
358357

359-
var newWindows = _winApiService.ListWindows();
358+
var newWindows = await Task.Run(() => _winApiService.ListWindows());
360359

361360
// remember the old windows to replace them with the new ones
362361
var oldSource = Source;
@@ -418,7 +417,7 @@ private void RefreshWindows()
418417
public void Initialize()
419418
{
420419
InstallMouseHook();
421-
RefreshWindows();
420+
_ = RefreshWindowsAsync();
422421
}
423422

424423
private void Start()

0 commit comments

Comments
 (0)