protected override void Complete(IntPtr userToken)
{
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"_context(set):{_context != null} userToken:{userToken}");
// If no flowing, just complete regularly.
if ((_flags & StateFlags.PostBlockStarted) == 0)
{
base.Complete(userToken);
return;
}
// At this point, IsCompleted is set and CompletedSynchronously is fixed. If it's synchronous, then we want to hold
// the completion for the CaptureOrComplete() call to avoid the context flow. If not, we know CaptureOrComplete() has completed.
if (CompletedSynchronously)
{
return;
}
ExecutionContext context = _context;
// If the context is being abandoned or wasn't captured (SuppressFlow, null AsyncCallback), just
// complete regularly, as long as CaptureOrComplete() has finished.
//
if (userToken != IntPtr.Zero || context == null)
{
base.Complete(userToken);
return;
}
ExecutionContext.Run(context, s => ((ContextAwareResult)s).CompleteCallback(), this);
}