From 5c913cc48a78e72e19d351270da1c3e8fbd914ce Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Wed, 12 Sep 2007 18:52:41 +0000 Subject: [PATCH] Improved AsyncProgressBar documentation and fine tuned the progress bar's behavior git-svn-id: file:///srv/devel/repo-conversion/nuwi@11 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Windows.Forms.csproj | 2 +- Source/AsyncProgressBar/AsyncProgressBar.cs | 12 +++++++++++- Source/ProgressReporter/ProgressReporterForm.cs | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Nuclex.Windows.Forms.csproj b/Nuclex.Windows.Forms.csproj index 4e36029..f0212e4 100644 --- a/Nuclex.Windows.Forms.csproj +++ b/Nuclex.Windows.Forms.csproj @@ -95,9 +95,9 @@ EmbeddedControlCollection - Form false ProgressReporterForm + Form ProgressReporterForm.cs diff --git a/Source/AsyncProgressBar/AsyncProgressBar.cs b/Source/AsyncProgressBar/AsyncProgressBar.cs index aa299f2..b623253 100644 --- a/Source/AsyncProgressBar/AsyncProgressBar.cs +++ b/Source/AsyncProgressBar/AsyncProgressBar.cs @@ -25,6 +25,10 @@ namespace Nuclex.Windows.Forms { this.updateProgressDelegate = new MethodInvoker(updateProgress); this.Disposed += new EventHandler(progressBarDisposed); + // Could probably use VolatileWrite() as well, but for consistency reasons + // this is an Interlocked call, too. Mixing different synchronization measures + // for a variable causes trouble so often that this raises a red flag + // whenever I see it :) Interlocked.Exchange(ref this.newProgress, -1.0f); } @@ -37,8 +41,10 @@ namespace Nuclex.Windows.Forms { // could be executing just now. But the final call to updateProgress() will not // have EndInvoke() called on it yet, so we do this here before the control // is finally disposed. - if(this.progressUpdateAsyncResult != null) + if(this.progressUpdateAsyncResult != null) { EndInvoke(this.progressUpdateAsyncResult); + this.progressUpdateAsyncResult = null; + } // CHECK: This method is only called on an explicit Dispose() of the control. // Microsoft officially states that it's allowed to call Control.BeginInvoke() @@ -73,6 +79,10 @@ namespace Nuclex.Windows.Forms { /// Synchronously updates the value visualized in the progress bar private void updateProgress() { + // Switch the style if the progress bar is still set to marquee mode + if(Style == ProgressBarStyle.Marquee) + Style = ProgressBarStyle.Blocks; + // Cache these to shorten the code that follows :) int minimum = base.Minimum; int maximum = base.Maximum; diff --git a/Source/ProgressReporter/ProgressReporterForm.cs b/Source/ProgressReporter/ProgressReporterForm.cs index 9077bd5..7f82494 100644 --- a/Source/ProgressReporter/ProgressReporterForm.cs +++ b/Source/ProgressReporter/ProgressReporterForm.cs @@ -16,6 +16,20 @@ namespace Nuclex.Windows.Forms { /// Blocking progress dialog that prevents the user from accessing the application /// window during all-blocking background processes. /// + /// + /// class Test : Nuclex.Support.Scheduling.ThreadOperation { + /// static void Main() { + /// Test myTest = new Test(); + /// myTest.Begin(); + /// Nuclex.Windows.Forms.ProgressReporterForm.Track(myTest); + /// myTest.End(); + /// } + /// protected override void Execute() { + /// for(int i = 0; i < 10000000; ++i) + /// OnAsyncProgressUpdated((float)i / 10000000.0f); + /// } + /// } + /// public partial class ProgressReporterForm : Form { /// Initializes a new progress reporter