From d082ad91d8c87e0972b5d340df8b4f5d07bb7015 Mon Sep 17 00:00:00 2001 From: Tako <53405089+Takoooooo@users.noreply.github.com> Date: Wed, 25 Aug 2021 19:34:54 +0300 Subject: [PATCH] Update AvaloniaSynchronizationContext to don't wrap exceptions to AggregateException when invoking from non-UI thread The code suggested by the user makes sense to me. Reproed issue with ` try { var ctx = SynchronizationContext.Current; await Task.Run(() => ctx.Send(state => throw new ArgumentException("hello"), null)); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (AggregateException ex) { Console.WriteLine(ex.Message); }` this code --- src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs index 1a78792173..326d1a3f53 100644 --- a/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs +++ b/src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs @@ -39,7 +39,7 @@ namespace Avalonia.Threading if (Dispatcher.UIThread.CheckAccess()) d(state); else - Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send).Wait(); + Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send).GetAwaiter().GetResult(); }