Skip to content

Commit

Permalink
Ensure exceptions flwo back correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaanstra committed Jan 14, 2022
1 parent 5c1b45b commit 7e8bc5c
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.ExceptionServices;
using System.Threading;
using Microsoft.System;

Expand Down Expand Up @@ -34,12 +35,28 @@ public override void Send(SendOrPostCallback d, object state)
else
{
var m = new ManualResetEvent(false);
ExceptionDispatchInfo edi = null;

m_dispatcherQueue.TryEnqueue(() =>
{
d(state);
m.Set();
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
}
}

Expand Down

0 comments on commit 7e8bc5c

Please sign in to comment.