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
This commit is contained in:
Markus Ewald 2007-09-12 18:52:41 +00:00
parent 4261d9b449
commit 5c913cc48a
3 changed files with 26 additions and 2 deletions

View File

@ -95,9 +95,9 @@
<Name>EmbeddedControlCollection</Name>
</Compile>
<Compile Include="Source\ProgressReporter\ProgressReporterForm.cs">
<SubType>Form</SubType>
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>ProgressReporterForm</Name>
<SubType>Form</SubType>
</Compile>
<Compile Include="Source\ProgressReporter\ProgressReporterForm.Designer.cs">
<DependentUpon>ProgressReporterForm.cs</DependentUpon>

View File

@ -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 {
/// <summary>Synchronously updates the value visualized in the progress bar</summary>
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;

View File

@ -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.
/// </summary>
/// <example>
/// 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 &lt; 10000000; ++i)
/// OnAsyncProgressUpdated((float)i / 10000000.0f);
/// }
/// }
/// </example>
public partial class ProgressReporterForm : Form {
/// <summary>Initializes a new progress reporter</summary>