diff --git a/src/Projections/Reunion/Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.cs b/src/Projections/Reunion/Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.cs
index f1f5a7e5c..301da6b9e 100644
--- a/src/Projections/Reunion/Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.cs
+++ b/src/Projections/Reunion/Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.cs
@@ -1,38 +1,68 @@
-using System;
-using System.Threading;
-using Microsoft.System;
-
-namespace Microsoft.System
-{
- ///
- /// DispatcherQueueSyncContext allows developers to await calls and get back onto the
- /// UI thread. Needs to be installed on the UI thread through DispatcherQueueSyncContext.SetForCurrentThread
- ///
- public class DispatcherQueueSynchronizationContext : SynchronizationContext
- {
- private readonly DispatcherQueue m_dispatcherQueue;
-
- public DispatcherQueueSynchronizationContext(DispatcherQueue dispatcherQueue)
- {
- m_dispatcherQueue = dispatcherQueue;
- }
-
- public override void Post(SendOrPostCallback d, object state)
- {
- if (d == null)
- throw new ArgumentNullException(nameof(d));
-
- m_dispatcherQueue.TryEnqueue(() => d(state));
- }
-
- public override void Send(SendOrPostCallback d, object state)
- {
- throw new NotSupportedException("Send not supported");
- }
-
- public override SynchronizationContext CreateCopy()
- {
- return new DispatcherQueueSynchronizationContext(m_dispatcherQueue);
- }
- }
+using System;
+using System.Runtime.ExceptionServices;
+using System.Threading;
+using Microsoft.System;
+
+namespace Microsoft.System
+{
+ ///
+ /// DispatcherQueueSyncContext allows developers to await calls and get back onto the
+ /// UI thread. Needs to be installed on the UI thread through DispatcherQueueSyncContext.SetForCurrentThread
+ ///
+ public class DispatcherQueueSynchronizationContext : SynchronizationContext
+ {
+ private readonly DispatcherQueue m_dispatcherQueue;
+
+ public DispatcherQueueSynchronizationContext(DispatcherQueue dispatcherQueue)
+ {
+ m_dispatcherQueue = dispatcherQueue;
+ }
+
+ public override void Post(SendOrPostCallback d, object state)
+ {
+ if (d == null)
+ throw new ArgumentNullException(nameof(d));
+
+ m_dispatcherQueue.TryEnqueue(() => d(state));
+ }
+
+ public override void Send(SendOrPostCallback d, object state)
+ {
+ if (m_dispatcherQueue.HasThreadAccess)
+ {
+ d(state);
+ }
+ else
+ {
+ var m = new ManualResetEvent(false);
+ ExceptionDispatchInfo edi = null;
+
+ m_dispatcherQueue.TryEnqueue(() =>
+ {
+ try
+ {
+ d(state);
+ }
+ catch (Exception ex)
+ {
+ edi = ExceptionDispatchInfo.Capture(ex);
+ }
+ finally
+ {
+ m.Set();
+ }
+ });
+ m.WaitOne();
+
+#pragma warning disable CA1508 // Avoid dead conditional code
+ edi?.Throw();
+#pragma warning restore CA1508 // Avoid dead conditional code
+ }
+ }
+
+ public override SynchronizationContext CreateCopy()
+ {
+ return new DispatcherQueueSynchronizationContext(m_dispatcherQueue);
+ }
+ }
}
\ No newline at end of file