|
3 | 3 | using System.Threading.Tasks;
|
4 | 4 | using Avalonia;
|
5 | 5 | using Avalonia.Controls;
|
| 6 | +using Avalonia.Threading; |
6 | 7 | using GitCredentialManager.Interop.Windows.Native;
|
7 | 8 | using GitCredentialManager.UI.Controls;
|
8 | 9 | using GitCredentialManager.UI.ViewModels;
|
@@ -38,30 +39,33 @@ public static Task ShowWindowAsync(Func<Window> windowFunc, object dataContext,
|
38 | 39 | {
|
39 | 40 | _isAppStarted = true;
|
40 | 41 |
|
41 |
| - var appRunning = new ManualResetEventSlim(); |
| 42 | + var appInitialized = new ManualResetEventSlim(); |
42 | 43 |
|
43 | 44 | // Fire and forget the Avalonia app main loop over to our dispatcher (running on the main/entry thread).
|
44 | 45 | // This action only returns on our dispatcher shutdown.
|
45 | 46 | Dispatcher.MainThread.Post(appCancelToken =>
|
46 | 47 | {
|
47 |
| - AppBuilder appBuilder = AppBuilder.Configure<AvaloniaApp>() |
| 48 | + AppBuilder.Configure<AvaloniaApp>() |
48 | 49 | .UsePlatformDetect()
|
49 | 50 | .LogToTrace()
|
50 | 51 | .SetupWithoutStarting();
|
51 | 52 |
|
52 |
| - appRunning.Set(); |
| 53 | + appInitialized.Set(); |
53 | 54 |
|
54 | 55 | // Run the application loop (only exit when the dispatcher is shutting down)
|
55 |
| - appBuilder.Instance.Run(appCancelToken); |
| 56 | + AvnDispatcher.UIThread.MainLoop(appCancelToken); |
56 | 57 | });
|
57 | 58 |
|
58 | 59 | // Wait for the action posted above to be dequeued from the dispatcher's job queue
|
59 | 60 | // and for the Avalonia framework (and their dispatcher) to be initialized.
|
60 |
| - appRunning.Wait(); |
| 61 | + appInitialized.Wait(); |
61 | 62 | }
|
62 | 63 |
|
63 | 64 | // Post the window action to the Avalonia dispatcher (which should be running)
|
64 |
| - return AvnDispatcher.UIThread.InvokeAsync(() => ShowWindowInternal(windowFunc, dataContext, parentHandle, ct)); |
| 65 | + return AvnDispatcher.UIThread.InvokeAsync( |
| 66 | + () => ShowWindowInternal(windowFunc, dataContext, parentHandle, ct), |
| 67 | + DispatcherPriority.Send |
| 68 | + ); |
65 | 69 | }
|
66 | 70 |
|
67 | 71 | private static Task ShowWindowInternal(Func<Window> windowFunc, object dataContext, IntPtr parentHandle, CancellationToken ct)
|
|
0 commit comments