Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
 public static void WaitAll(params Task[] ts)
 {
     DeadlockDetection.DisableThreadAbort();
     try
     {
         Task.WaitAll(ts);
     }
     finally
     {
         DeadlockDetection.EnableThreadAbort();
     }
 }
Ejemplo n.º 3
0
 public static XmlReader ExecuteXmlReader(SqlCommand command)
 {
     DeadlockDetection.DisableThreadAbort();
     try
     {
         return(command.ExecuteXmlReader());
     }
     finally
     {
         DeadlockDetection.EnableThreadAbort();
     }
 }
Ejemplo n.º 4
0
 public static int ExecuteNonQuery(SqlCommand command)
 {
     DeadlockDetection.DisableThreadAbort();
     try
     {
         return(command.ExecuteNonQuery());
     }
     finally
     {
         DeadlockDetection.DisableThreadAbort();
     }
 }
Ejemplo n.º 5
0
 public static T GetResult <T>(Task <T> result)
 {
     DeadlockDetection.DisableThreadAbort();
     try
     {
         return(result.Result);
     }
     finally
     {
         DeadlockDetection.EnableThreadAbort();
     }
 }
Ejemplo n.º 6
0
 public static void WaitAllNullable(params Task[] ts)
 {
     DeadlockDetection.DisableThreadAbort();
     try
     {
         Task[] tasks = ts.Where(t => t != null).ToArray();
         Task.WaitAll(tasks);
     }
     finally
     {
         DeadlockDetection.EnableThreadAbort();
     }
 }