Esempio n. 1
0
        private static IteratorContext ExecuteTaskHelper(ITask currentTask)
        {
            if (currentTask.LinkedIterator != null)
            {
                IteratorContext iteratorContext = (IteratorContext)currentTask.LinkedIterator;
                if (CausalityThreadContext.IsEmpty(iteratorContext._causalities))
                {
                    Dispatcher.ClearCausalities();
                }
                else
                {
                    Dispatcher.SetCurrentThreadCausalities(iteratorContext._causalities.Clone());
                }
            }
            else
            {
                Dispatcher.TransferCausalitiesFromTaskToCurrentThread(currentTask);
            }
            if (Debugger.IsAttached)
            {
                CausalityThreadContext currentThreadCausalities = Dispatcher.GetCurrentThreadCausalities();
                if (!CausalityThreadContext.IsEmpty(currentThreadCausalities) && CausalityThreadContext.RequiresDebugBreak(currentThreadCausalities))
                {
                    Debugger.Break();
                }
            }
            IEnumerator <ITask> enumerator = currentTask.Execute();

            if (enumerator != null)
            {
                return(new IteratorContext(enumerator, Dispatcher.GetCurrentThreadCausalities()));
            }
            return(null);
        }
Esempio n. 2
0
 private static void MoveIterator(ref ITask currentTask, IteratorContext iteratorContext, ref Handler finalizer)
 {
     lock (iteratorContext)
     {
         bool flag2 = false;
         try
         {
             flag2 = !iteratorContext._iterator.MoveNext();
             if (!flag2)
             {
                 iteratorContext._causalities = Dispatcher.GetCurrentThreadCausalities();
                 currentTask = iteratorContext._iterator.Current;
                 currentTask.ArbiterCleanupHandler = finalizer;
                 finalizer = null;
             }
             else
             {
                 if (currentTask != null)
                 {
                     finalizer = currentTask.ArbiterCleanupHandler;
                 }
                 else
                 {
                     finalizer = null;
                 }
                 currentTask = null;
             }
         }
         catch (Exception)
         {
             iteratorContext._iterator.Dispose();
             throw;
         }
         finally
         {
             if (flag2)
             {
                 iteratorContext._iterator.Dispose();
             }
         }
     }
 }