From c21ba759cc1aba5ae5ac67ec4d448ddad91aaa47 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Wed, 26 Mar 2008 19:52:28 +0000 Subject: [PATCH] Renamed FailableOperation to Request, this is a much shorter name that better represents the concept implemented by the class git-svn-id: file:///srv/devel/repo-conversion/nusu@62 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Support (x86).csproj | 2 +- Source/Scheduling/Operation.cs | 2 +- .../Internal/ObservedWeightedProgression.cs | 14 ++++- .../{FailableProgression.cs => Request.cs} | 56 +++++++++++-------- 4 files changed, 47 insertions(+), 27 deletions(-) rename Source/Tracking/{FailableProgression.cs => Request.cs} (67%) diff --git a/Nuclex.Support (x86).csproj b/Nuclex.Support (x86).csproj index dbee5ed..a8b4444 100644 --- a/Nuclex.Support (x86).csproj +++ b/Nuclex.Support (x86).csproj @@ -148,7 +148,7 @@ - + diff --git a/Source/Scheduling/Operation.cs b/Source/Scheduling/Operation.cs index ceaadac..850769b 100644 --- a/Source/Scheduling/Operation.cs +++ b/Source/Scheduling/Operation.cs @@ -26,7 +26,7 @@ using Nuclex.Support.Tracking; namespace Nuclex.Support.Scheduling { /// Base class for observable operations running in the background - public abstract class Operation : FailableProgression { + public abstract class Operation : Request { /// Launches the background operation public abstract void Start(); diff --git a/Source/Tracking/Internal/ObservedWeightedProgression.cs b/Source/Tracking/Internal/ObservedWeightedProgression.cs index 4079ac7..d454d4a 100644 --- a/Source/Tracking/Internal/ObservedWeightedProgression.cs +++ b/Source/Tracking/Internal/ObservedWeightedProgression.cs @@ -48,6 +48,7 @@ namespace Nuclex.Support.Tracking { ) { this.weightedProgression = weightedProgression; + // See if this progression has already ended (initial check for performance) if(weightedProgression.Progression.Ended) { this.progress = 1.0f; @@ -60,8 +61,17 @@ namespace Nuclex.Support.Tracking { this.weightedProgression.Progression.AsyncEnded += new EventHandler(asyncEnded); - this.weightedProgression.Progression.AsyncProgressUpdated += - new EventHandler(asyncProgressUpdated); + // Check whether this progression might have ended before we were able to + // attach ourselfes to its event. If so, don't bother registering to the + // other event and (important) set our progress to 1.0 because, since we + // might not have gotten the 'Ended' event, it might otherwise stay at 0.0 + // even though the progression is in the 'Ended' state. + if(weightedProgression.Progression.Ended) { + this.progress = 1.0f; + } else { + this.weightedProgression.Progression.AsyncProgressUpdated += + new EventHandler(asyncProgressUpdated); + } } } diff --git a/Source/Tracking/FailableProgression.cs b/Source/Tracking/Request.cs similarity index 67% rename from Source/Tracking/FailableProgression.cs rename to Source/Tracking/Request.cs index 720b818..154eb4d 100644 --- a/Source/Tracking/FailableProgression.cs +++ b/Source/Tracking/Request.cs @@ -1,3 +1,23 @@ +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2008 Nuclex Development Labs + +This library is free software; you can redistribute it and/or +modify it under the terms of the IBM Common Public License as +published by the IBM Corporation; either version 1.0 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +IBM Common Public License for more details. + +You should have received a copy of the IBM Common Public +License along with this library +*/ +#endregion + using System; using System.Collections.Generic; @@ -17,17 +37,17 @@ namespace Nuclex.Support.Tracking { /// OnAsyncEnded(), no matter what the outcome of your background operation is. /// /// - public class FailableProgression : Progression { + public class Request : Progression { - #region class EndedDummyProgression + #region class EndedDummyRequest - /// Dummy progression that is always in the ended state - private class EndedDummyProgression : FailableProgression { - /// Creates a new successfully completed dummy progression - public EndedDummyProgression() : this(null) { } - /// Creates a new failed dummy progression + /// Dummy request that is always in the ended state + private class EndedDummyRequest : Request { + /// Creates a new successfully completed dummy request + public EndedDummyRequest() : this(null) { } + /// Creates a new failed dummy request /// Exception that caused the dummy to fail - public EndedDummyProgression(Exception exception) { + public EndedDummyRequest(Exception exception) { OnAsyncEnded(); // Only call SetException() if an actual exception was provided. Who knows what @@ -37,17 +57,17 @@ namespace Nuclex.Support.Tracking { } } - #endregion // EndedDummyProgression + #endregion // EndedDummyRequest - /// Creates a new failed dummy progression + /// Creates a new failed dummy request /// /// Exception that supposedly caused the progression to fail /// /// - /// A failed progression that reports the provided exception as cause for its failure + /// A failed request that reports the provided exception as cause for its failure /// - public static FailableProgression CreateFailedDummyProgression(Exception exception) { - return new EndedDummyProgression(exception); + public static Request CreateFailedDummyRequest(Exception exception) { + return new EndedDummyRequest(exception); } /// Waits for the background operation to end @@ -59,14 +79,6 @@ namespace Nuclex.Support.Tracking { /// public virtual void Join() { - // By design, end can only be called once! - lock(this) { - if(this.endCalled) - throw new InvalidOperationException("End() has already been called"); - - this.endCalled = true; - } - // If the progression itself hasn't ended yet, block the caller until it has. if(!Ended) WaitHandle.WaitOne(); @@ -101,8 +113,6 @@ namespace Nuclex.Support.Tracking { /// Exception that occured while the operation was executing private volatile Exception occuredException; - /// Whether the End() method has been called already - private volatile bool endCalled; }