/// <summary>
 /// Registers a delegate that will be called when this System.Threading.CancellationToken  is canceled.
 /// </summary>
 /// <param name="callback">The delegate to be executed when the System.Threading.CancellationToken is canceled.</param>
 /// <param name="useSynchronizationContext">A value that indicates whether to capture the current System.Threading.SynchronizationContext and use it when invoking the callback.</param>
 /// <returns>The System.Threading.CancellationTokenRegistration instance that can be used to deregister the callback.</returns>
 /// <exception cref="System.ArgumentNullException">callback is null</exception>
 public CancellationTokenRegistration Register(Action callback, bool useSynchronizationContext)
 {
     callback = callback ?? throw new ArgumentNullException("callback");
     if (source.IsCancellationRequested)
     {
         callback();
     }
     else if (source != null)
     {
         return(source.NotifyOnCancelled(callback, useSynchronizationContext));
     }
     return(new CancellationTokenRegistration());
 }