Exemplo n.º 1
0
 /// <summary>
 /// End a progress tracking level. When a transition to zero active levels occurs, then and only then,
 /// is a Progressing event raised with a percent value of 100.
 /// Calls to NotifyLevelStart() and NotifyLevelFinished() must be balanced.
 /// </summary>
 public void NotifyLevelFinished()
 {
     Invariant();
     lock (_progressLevelLock)
     {
         if (_progressLevel == 0)
         {
             throw new InvalidOperationException("Call to NotifyLevelFinished() without prior call to NotifyLevelStart().");
         }
         if (--_progressLevel > 0)
         {
             return;
         }
         --_progressLevel;
     }
     ProgressEventArgs e = new ProgressEventArgs(100);
     OnProgressing(e);
 }
Exemplo n.º 2
0
 protected virtual void OnProgressing(ProgressEventArgs e)
 {
     EventHandler<ProgressEventArgs> handler = Progressing;
     if (handler != null)
     {
         _synchronizationContext.Send(
             (object state) =>
             {
                 handler(this, (ProgressEventArgs)e);
             },
             e);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add to the count of work having been performed. May lead to a Progressing event.
 /// </summary>
 /// <param name="count">The amount of work having been performed in this step.</param>
 public void AddCount(long count)
 {
     Invariant();
     if (count <= 0)
     {
         return;
     }
     lock (_progressLock)
     {
         _current += count;
         if (_stopwatch.Elapsed < _nextProgressTime)
         {
             return;
         }
         _nextProgressTime = _stopwatch.Elapsed.Add(ProgressTimeInterval);
     }
     ProgressEventArgs e = new ProgressEventArgs(Percent);
     OnProgressing(e);
 }