|
1 | 1 | using System.Collections.ObjectModel;
|
2 | 2 | using System.ComponentModel;
|
3 |
| -using System.Diagnostics.CodeAnalysis; |
4 | 3 | using System.Drawing;
|
5 | 4 | using System.Runtime.InteropServices;
|
6 | 5 | using System.Threading.Channels;
|
@@ -37,7 +36,7 @@ public sealed partial class MainViewModel : IDisposable
|
37 | 36 | // ReSharper disable once MemberCanBePrivate.Global
|
38 | 37 | public ICollectionView WindowsOrdered { get; }
|
39 | 38 |
|
40 |
| - public RelayCommand RefreshWindowsCommand { get; } |
| 39 | + public AsyncRelayCommand RefreshWindowsCommand { get; } |
41 | 40 | public RelayCommand StartCommand { get; }
|
42 | 41 | public RelayCommand StopCommand { get; }
|
43 | 42 |
|
@@ -94,7 +93,7 @@ public MainViewModel(
|
94 | 93 | _winApiService = winApiService;
|
95 | 94 | _mouseHook = mouseHook;
|
96 | 95 |
|
97 |
| - RefreshWindowsCommand = new RelayCommand(RefreshWindows); |
| 96 | + RefreshWindowsCommand = new AsyncRelayCommand(RefreshWindowsAsync); |
98 | 97 | StartCommand = new RelayCommand(Start);
|
99 | 98 | StopCommand = new RelayCommand(Stop);
|
100 | 99 |
|
@@ -352,11 +351,11 @@ private async Task RunUpdateMouseHookRectsLoopAsync(CancellationToken token)
|
352 | 351 | }
|
353 | 352 | }
|
354 | 353 |
|
355 |
| - private void RefreshWindows() |
| 354 | + private async Task RefreshWindowsAsync() |
356 | 355 | {
|
357 | 356 | _logger.LogInformation("Refreshing windows");
|
358 | 357 |
|
359 |
| - var newWindows = _winApiService.ListWindows(); |
| 358 | + var newWindows = await Task.Run(() => _winApiService.ListWindows()); |
360 | 359 |
|
361 | 360 | // remember the old windows to replace them with the new ones
|
362 | 361 | var oldSource = Source;
|
@@ -418,7 +417,7 @@ private void RefreshWindows()
|
418 | 417 | public void Initialize()
|
419 | 418 | {
|
420 | 419 | InstallMouseHook();
|
421 |
| - RefreshWindows(); |
| 420 | + _ = RefreshWindowsAsync(); |
422 | 421 | }
|
423 | 422 |
|
424 | 423 | private void Start()
|
|
0 commit comments