public static void WaitAndUnwrapException(Task t) { DeadlockDetection.DisableThreadAbort(); try { t.Wait(); } catch (AggregateException ae) { // The callers of this API may not expect AggregateException, so throw the inner exception // If AggregateException contains more than one InnerExceptions, throw it out as it is, // because that is unexpected if ((ae.InnerExceptions != null) && (ae.InnerExceptions.Count == 1)) { if (ae.InnerException != null) { ExceptionDispatchInfo info = ExceptionDispatchInfo.Capture(ae.InnerException); info.Throw(); } } throw; } finally { DeadlockDetection.EnableThreadAbort(); } }
public static void WaitAll(params Task[] ts) { DeadlockDetection.DisableThreadAbort(); try { Task.WaitAll(ts); } finally { DeadlockDetection.EnableThreadAbort(); } }
public static XmlReader ExecuteXmlReader(SqlCommand command) { DeadlockDetection.DisableThreadAbort(); try { return(command.ExecuteXmlReader()); } finally { DeadlockDetection.EnableThreadAbort(); } }
public static int ExecuteNonQuery(SqlCommand command) { DeadlockDetection.DisableThreadAbort(); try { return(command.ExecuteNonQuery()); } finally { DeadlockDetection.DisableThreadAbort(); } }
public static T GetResult <T>(Task <T> result) { DeadlockDetection.DisableThreadAbort(); try { return(result.Result); } finally { DeadlockDetection.EnableThreadAbort(); } }
public static void WaitAllNullable(params Task[] ts) { DeadlockDetection.DisableThreadAbort(); try { Task[] tasks = ts.Where(t => t != null).ToArray(); Task.WaitAll(tasks); } finally { DeadlockDetection.EnableThreadAbort(); } }