コード例 #1
0
 public Progress(BasicAmbientProgress progressService, IAmbientProgress?parentProgress, float startPortion, float portionPart, string?prefix = null, bool inheritCancellationSource = true)
 {
     _tracker     = progressService;
     _prefix      = prefix ?? "";
     _currentItem = "";
     if (startPortion < 0.0 || startPortion > 1.0)
     {
         throw new ArgumentOutOfRangeException(nameof(startPortion), "The start portion must be between 0.0 and 1.0, inclusive!");
     }
     if (portionPart < 0.0 || portionPart > 1.0)
     {
         throw new ArgumentOutOfRangeException(nameof(portionPart), "The portion part must be between 0.0 and 1.0, inclusive!");
     }
     if (startPortion + portionPart > 1.0)
     {
         throw new ArgumentOutOfRangeException(nameof(portionPart), "The sum of the start portion and portion part must be 1.0 or less!");
     }
     _parentProgress = parentProgress;
     _startPortion   = startPortion;
     _portionPart    = portionPart;
     if (_inheritedCancelSource = inheritCancellationSource) // note that this is an ASSIGNMENT in addition to a test
     {
         _cancelSource = parentProgress?.CancellationTokenSource ?? new AmbientCancellationTokenSource();
     }
     else
     {
         _cancelSource = new AmbientCancellationTokenSource();
     }
     progressService.PushSubProgress(this);
 }
コード例 #2
0
        public void ResetCancellation(CancellationTokenSource?cancellationTokenSource = null)
        {
            AmbientCancellationTokenSource?cancelSource = (cancellationTokenSource == null) ? new AmbientCancellationTokenSource(null) :  new AmbientCancellationTokenSource(cancellationTokenSource);

            // dispose of any previously-held cancellation token source and swap in the new one
            if (!_inheritedCancelSource)
            {
                _cancelSource.Dispose();
            }
            _inheritedCancelSource = false;
            _cancelSource          = cancelSource;
        }
コード例 #3
0
        public void ResetCancellation(TimeSpan timeout)
        {
            AmbientCancellationTokenSource cancelSource = new AmbientCancellationTokenSource(timeout);

            // dispose of any previously-held cancellation token source and swap in the new one
            if (!_inheritedCancelSource)
            {
                _cancelSource.Dispose();
            }
            _inheritedCancelSource = false;
            _cancelSource          = cancelSource;
        }