private void InvokeCallbacks()
        {
            var value = Interlocked.Exchange(ref _callback, _callbackCompletionSentinel);

            if (value != null)
            {
                var invokeAsync = (_flags & _flagRunContinuationsAsynchronously) != 0;

                if (value is CallbackCollection callbackList)
                {
                    lock (callbackList)
                    {
                        callbackList.Invoke(invokeAsync);
                    }
                }
                else if (invokeAsync)
                {
                    CallbackUtility.InvokeCompletionCallbackAsync(this, value, SynchronizationContext.Current);
                }
                else
                {
                    CallbackUtility.InvokeCompletionCallback(this, value);
                }
            }
        }
 private void InvokeCompletionCallback(object continuation, SynchronizationContext syncContext)
 {
     if ((_flags & _flagRunContinuationsAsynchronously) != 0)
     {
         CallbackUtility.InvokeCompletionCallbackAsync(this, continuation, syncContext);
     }
     else if (syncContext == null || syncContext == SynchronizationContext.Current)
     {
         CallbackUtility.InvokeCompletionCallback(this, continuation);
     }
     else
     {
         syncContext.Post(args => CallbackUtility.InvokeCompletionCallback(this, args), continuation);
     }
 }