Skip to content

Commit 99e4c69

Browse files
committed
ui: fix deadlock in Avalonia runloop start on Windows
1 parent bd742ce commit 99e4c69

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/shared/Core/UI/AvaloniaUi.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using Avalonia;
55
using Avalonia.Controls;
6+
using Avalonia.Threading;
67
using GitCredentialManager.Interop.Windows.Native;
78
using GitCredentialManager.UI.Controls;
89
using GitCredentialManager.UI.ViewModels;
@@ -38,30 +39,33 @@ public static Task ShowWindowAsync(Func<Window> windowFunc, object dataContext,
3839
{
3940
_isAppStarted = true;
4041

41-
var appRunning = new ManualResetEventSlim();
42+
var appInitialized = new ManualResetEventSlim();
4243

4344
// Fire and forget the Avalonia app main loop over to our dispatcher (running on the main/entry thread).
4445
// This action only returns on our dispatcher shutdown.
4546
Dispatcher.MainThread.Post(appCancelToken =>
4647
{
47-
AppBuilder appBuilder = AppBuilder.Configure<AvaloniaApp>()
48+
AppBuilder.Configure<AvaloniaApp>()
4849
.UsePlatformDetect()
4950
.LogToTrace()
5051
.SetupWithoutStarting();
5152

52-
appRunning.Set();
53+
appInitialized.Set();
5354

5455
// Run the application loop (only exit when the dispatcher is shutting down)
55-
appBuilder.Instance.Run(appCancelToken);
56+
AvnDispatcher.UIThread.MainLoop(appCancelToken);
5657
});
5758

5859
// Wait for the action posted above to be dequeued from the dispatcher's job queue
5960
// and for the Avalonia framework (and their dispatcher) to be initialized.
60-
appRunning.Wait();
61+
appInitialized.Wait();
6162
}
6263

6364
// 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+
);
6569
}
6670

6771
private static Task ShowWindowInternal(Func<Window> windowFunc, object dataContext, IntPtr parentHandle, CancellationToken ct)

0 commit comments

Comments
 (0)