public static void ExecuteTask(this ITaskDispatcher self, Action action, int timeoutMs) { try { self.QueueTask(action).Wait(timeoutMs); } catch (AggregateException ex) { throw ex.Flatten().InnerException.PrepareForRethrow(); } }
public static T ExecuteTask <T>(this ITaskDispatcher self, Func <T> action, int timeoutMs) { try { using (Task <T> task = self.QueueTask <T>(action)) { if (!task.Wait(timeoutMs)) { throw new TimeoutException("Timed out waiting on task"); } return(task.Result); } } catch (AggregateException ex) { throw ex.Flatten().InnerException.PrepareForRethrow(); } }