Exemplo n.º 1
0
            private void MoveNext(Thread?threadPoolThread)
            {
                Debug.Assert(!IsCompleted);

                bool loggingOn = AsyncCausalityTracer.LoggingOn;

                if (loggingOn)
                {
                    AsyncCausalityTracer.TraceSynchronousWorkStart(this, CausalitySynchronousWork.Execution);
                }

                ExecutionContext?context = Context;

                if (context == null)
                {
                    Debug.Assert(StateMachine != null);
                    StateMachine.MoveNext();
                }
                else
                {
                    if (threadPoolThread is null)
                    {
                        ExecutionContext.RunInternal(context, s_callback, this);
                    }
                    else
                    {
                        ExecutionContext.RunFromThreadPoolDispatchLoop(threadPoolThread, context, s_callback, this);
                    }
                }

                if (IsCompleted)
                {
                    // If async debugging is enabled, remove the task from tracking.
                    if (System.Threading.Tasks.Task.s_asyncDebuggingEnabled)
                    {
                        System.Threading.Tasks.Task.RemoveFromActiveTasks(this);
                    }

                    // Clear out state now that the async method has completed.
                    // This avoids keeping arbitrary state referenced by lifted locals
                    // if this Task / state machine box is held onto.
                    StateMachine = default;
                    Context      = default;

#if !CORERT
                    // In case this is a state machine box with a finalizer, suppress its finalization
                    // as it's now complete.  We only need the finalizer to run if the box is collected
                    // without having been completed.
                    if (AsyncMethodBuilderCore.TrackAsyncMethodCompletion)
                    {
                        GC.SuppressFinalize(this);
                    }
#endif
                }

                if (loggingOn)
                {
                    AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalitySynchronousWork.Execution);
                }
            }
Exemplo n.º 2
0
 internal static Action OutputAsyncCausalityEvents(Task task, Action continuation) =>
 CreateContinuationWrapper(continuation, (innerContinuation, innerTask) =>
 {
     AsyncCausalityTracer.TraceSynchronousWorkStart(CausalityTraceLevel.Required, innerTask.Id, CausalitySynchronousWork.Execution);
     innerContinuation.Invoke();     // Invoke the original continuation
     AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalityTraceLevel.Required, CausalitySynchronousWork.Execution);
 }, task);
Exemplo n.º 3
0
 // Token: 0x06005D15 RID: 23829 RVA: 0x00146578 File Offset: 0x00144778
 private Action OutputAsyncCausalityEvents(Task innerTask, Action continuation)
 {
     return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, delegate
     {
         AsyncCausalityTracer.TraceSynchronousWorkStart(CausalityTraceLevel.Required, innerTask.Id, CausalitySynchronousWork.Execution);
         continuation();
         AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalityTraceLevel.Required, CausalitySynchronousWork.Execution);
     }, innerTask));
 }
Exemplo n.º 4
0
 internal static void TraceSynchronousWorkStart(Task task)
 {
     AsyncCausalityTracer.TraceSynchronousWorkStart(CausalityTraceLevel.Required, task.Id, CausalitySynchronousWork.Execution);
 }