Skip to content

Commit

Permalink
Merge pull request #83 from zerodev1200/fix-synccontext-thread-handling
Browse files Browse the repository at this point in the history
Improve synchronization handling in event dispatcher
  • Loading branch information
neuecc authored Oct 21, 2024
2 parents c1c9d86 + 43357a5 commit a4d80bd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ObservableCollections/ICollectionEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ public SynchronizationContextCollectionEventDispatcher(SynchronizationContext sy

public void Post(CollectionEventDispatcherEventArgs ev)
{
synchronizationContext.Post(callback, ev);
if (SynchronizationContext.Current == null)
{
// non-UI thread, post the event asynchronously
synchronizationContext.Post(callback, ev);
}
else
{
// UI thread, send the event synchronously
synchronizationContext.Send(callback, ev);
}
}

static void SendOrPostCallback(object? state)
Expand Down

0 comments on commit a4d80bd

Please sign in to comment.