/// <summary> Ends this task, firing the 100% complete event if necessary, and pops the Progress stack. /// </summary> /// <param name="completedSuccessfully"> /// Determines if the 100% complete event should be fired or skipped. /// </param> private void EndTask(bool completedSuccessfully) { // Only dispose once: if (this.isEnded) { return; } this.isEnded = true; // Report the 100% progress: if (completedSuccessfully) { this.OnProgressChanged(null); } // Report the progress Ended: if (this.progressEndedCallback != null) { this.progressEndedCallback(new ProgressChangedInfo(new ProgressInfo(100f, taskKey, taskArg), null)); this.progressEndedCallback = null; } // Clear events: this.progressChangedCallback = null; // Clear calculator: (dispose if possible) var calcDispose = this.calculator as IDisposable; if (calcDispose != null) { calcDispose.Dispose(); } this.calculator = null; // DEBUG: Make sure "this" is on the top of the stack. // This might not be the case if you fail to dispose/end a task, // or if you dispose it from a thread other than the one that created it. // Who would do such a thing?!? while (currentTask != this && currentTask != null) { Debug.Write("Warning: a Progress Task was not properly disposed."); currentTask.Dispose(); } Debug.Assert(currentTask != null, "A Progress Task must be disposed from the thread that created it."); // Pop the stack: currentTask = this.parent; }
/// <summary> Pushes a new task to the top of the stack. /// </summary> /// <param name="calculator"></param> public ProgressTask(IProgressCalculator calculator) { this.calculator = calculator; // Push this new task on the top of the task stack: this.parent = currentTask; currentTask = this; // Calculate the new maximum depth: if (this.parent == null) { this.maximumDepth = ProgressDepth.Auto; } else { this.maximumDepth = parent.maximumDepth - 1; } }
private void Progress_Starting(ProgressTask progressTask) { // We're only looking for this specific task: if (this.currentTask != null || progressTask.TaskKey != this.TaskKey) { return; } // Keep track of this task so we can poll it: this.currentTask = progressTask; progressTask.EnablePolling(this.MaximumDepth); // Start polling for progress: Timer.Start(); progressTask.SetCallbackEnded(this.OnProgressEnding); }
private void StopPolling() { // Stop polling: var timer = this.Timer; if (timer != null) { Timer.Stop(); } // Clear the task: this.currentTask = null; }
/// <summary> Ends this task, firing the 100% complete event if necessary, and pops the Progress stack. /// </summary> /// <param name="completedSuccessfully"> /// Determines if the 100% complete event should be fired or skipped. /// </param> private void EndTask(bool completedSuccessfully) { // Only dispose once: if (this.isEnded) return; this.isEnded = true; // Report the 100% progress: if (completedSuccessfully) { this.OnProgressChanged(null); } // Report the progress Ended: if (this.progressEndedCallback != null) { this.progressEndedCallback(new ProgressChangedInfo(new ProgressInfo(100f, taskKey, taskArg), null)); this.progressEndedCallback = null; } // Clear events: this.progressChangedCallback = null; // Clear calculator: (dispose if possible) var calcDispose = this.calculator as IDisposable; if (calcDispose != null) calcDispose.Dispose(); this.calculator = null; // DEBUG: Make sure "this" is on the top of the stack. // This might not be the case if you fail to dispose/end a task, // or if you dispose it from a thread other than the one that created it. // Who would do such a thing?!? while (currentTask != this && currentTask != null) { Debug.Write("Warning: a Progress Task was not properly disposed."); currentTask.Dispose(); } Debug.Assert(currentTask != null, "A Progress Task must be disposed from the thread that created it."); // Pop the stack: currentTask = this.parent; }