Esempio n. 1
0
 public static T RunTask <T>(Func <Task <T> > task)
 {
     if (isProfiling)
     {
         return(QueueSynchronizationContext.RunTask(task));
     }
     else
     {
         return(task().GetAwaiter().GetResult());
     }
 }
Esempio n. 2
0
        public static void RunTask(Func <Task> task)
        {
            var last = SynchronizationContext.Current;
            var c    = new QueueSynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(c);
            var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            var runningTask   = Task <Task> .Factory.StartNew(task, CancellationToken.None, TaskCreationOptions.None, taskScheduler).Unwrap();

            c.Run(runningTask);
            SynchronizationContext.SetSynchronizationContext(last);
        }