public static void Run(Func <object> performStep) { var oldSyncContext = SynchronizationContext.Current; try { var asyncSyncContext = new AsyncTestSyncContext(); SetSynchronizationContext(asyncSyncContext); var result = performStep(); var task = result as Task; if (task != null) { try { task.Wait(); } catch (AggregateException ae) { var innerException = ae.InnerException; ExceptionProcessor.PreserveStackTrace(innerException); throw innerException; } } else { var ex = asyncSyncContext.WaitForCompletion(); if (ex != null) { ExceptionProcessor.PreserveStackTrace(ex); throw ex; } } } finally { SetSynchronizationContext(oldSyncContext); } }
public static void Run(Func <object> performStep) { var oldSyncContext = SynchronizationContext.Current; try { var asyncSyncContext = new AsyncTestSyncContext(); SetSynchronizationContext(asyncSyncContext); performStep(); { var ex = asyncSyncContext.WaitForCompletion(); if (ex != null) { ExceptionProcessor.PreserveStackTrace(ex); throw ex; } } } finally { SetSynchronizationContext(oldSyncContext); } }