Skip to content

Commit 7e8bc5c

Browse files
committed
Ensure exceptions flwo back correctly.
1 parent 5c1b45b commit 7e8bc5c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Projections/Reunion/Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.ExceptionServices;
23
using System.Threading;
34
using Microsoft.System;
45

@@ -34,12 +35,28 @@ public override void Send(SendOrPostCallback d, object state)
3435
else
3536
{
3637
var m = new ManualResetEvent(false);
38+
ExceptionDispatchInfo edi = null;
39+
3740
m_dispatcherQueue.TryEnqueue(() =>
3841
{
39-
d(state);
40-
m.Set();
42+
try
43+
{
44+
d(state);
45+
}
46+
catch (Exception ex)
47+
{
48+
edi = ExceptionDispatchInfo.Capture(ex);
49+
}
50+
finally
51+
{
52+
m.Set();
53+
}
4154
});
4255
m.WaitOne();
56+
57+
#pragma warning disable CA1508 // Avoid dead conditional code
58+
edi?.Throw();
59+
#pragma warning restore CA1508 // Avoid dead conditional code
4360
}
4461
}
4562

0 commit comments

Comments
 (0)