Skip to content

Commit d03a65b

Browse files
authored
Update Show method to marshal to UI thread
Ensure notifications are shown on the UI thread. Any caller that does notificationService.Show( ) or notificationService.TryAsync( ) from a background thread directly hits WindowNotificationManager.Show which hits line 48 raw with no UI thread marshalling. Leading to unhandled exception in Avalonia and crashes. This follows the same pattern used by ShowAsyncCore which wraps every toast call in Dispatcher.UIThread.Invoke( ). Without it, NotificationService.Show(INotification notification) on L48 is called from thread-pool threads (Polly continuations, Task.Run blocks) after HTTP failures exhaust retries and surface a notification.
1 parent f9e6f1c commit d03a65b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

StabilityMatrix.Avalonia/Services/NotificationService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ public void Initialize(
4545
};
4646
}
4747

48-
public void Show(INotification notification)
48+
public void Show(INotification notification)
49+
{
50+
// Must marshal to UI thread - WindowNotificationManager requires it
51+
if (Dispatcher.UIThread.CheckAccess())
4952
{
5053
notificationManager?.Show(notification);
5154
}
55+
else
56+
{
57+
Dispatcher.UIThread.Post(() => notificationManager?.Show(notification));
58+
}
59+
}
5260

5361
/// <inheritdoc />
5462
public Task ShowPersistentAsync(NotificationKey key, DesktopNotifications.Notification notification)

0 commit comments

Comments
 (0)