Exemple #1
0
        /// <summary>
        /// Cancels the current set of <see cref="CancellationToken"/> (if there are any token objects on issue) and starts a new set.
        /// </summary>
        /// <param name="pParentContext">Context for trace messages.</param>
        /// <remarks>
        /// The <see cref="Count"/> is reset to zero.
        /// </remarks>
        public void Cancel(cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cCancellationManager), nameof(Cancel));

            if (mDisposed)
            {
                throw new ObjectDisposedException(nameof(cCancellationManager));
            }

            lock (mCurrentCancellationSetLock)
            {
                if (mCurrentCancellationSet.Count == 0)
                {
                    return;
                }
                mCurrentCancellationSet.Cancel();
                mCurrentCancellationSet = new cCancellationSet(mCountChanged);
                mCountChanged?.Invoke(lContext);
            }
        }
Exemple #2
0
 /// <summary>
 /// Initialises a new instance with the specified callback to be used when <see cref="Count"/> changes.
 /// </summary>
 /// <param name="pCountChanged"></param>
 public cCancellationManager(Action <cTrace.cContext> pCountChanged)
 {
     mCountChanged           = pCountChanged;
     mCurrentCancellationSet = new cCancellationSet(mCountChanged);
 }
Exemple #3
0
 /// <summary>
 /// Initialises a new instance.
 /// </summary>
 public cCancellationManager()
 {
     mCountChanged           = null;
     mCurrentCancellationSet = new cCancellationSet(null);
 }