add handling for SynchronizationContext

This commit is contained in:
zerodev1200 2024-10-20 03:06:42 +09:00
parent c1c9d86ff7
commit 43357a5198

View File

@ -35,8 +35,17 @@ namespace ObservableCollections
public void Post(CollectionEventDispatcherEventArgs 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)
{