From 10d6533b50f8577a1c2c31bc1ee02c8d512a24ad Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Thu, 28 May 2009 19:55:48 +0000 Subject: [PATCH] Added an obvious, simple and important optimization: when Transaction.Wait() is called, the transaction will not create a WaitHandle if it has already ended git-svn-id: file:///srv/devel/repo-conversion/nusu@142 d2e56fa2-650e-0410-a79f-9358c0239efd --- Source/Tracking/Transaction.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Tracking/Transaction.cs b/Source/Tracking/Transaction.cs index 51ea54d..3a4a1f3 100644 --- a/Source/Tracking/Transaction.cs +++ b/Source/Tracking/Transaction.cs @@ -128,7 +128,9 @@ namespace Nuclex.Support.Tracking { /// Waits until the background process finishes public virtual void Wait() { - WaitHandle.WaitOne(); + if(!this.ended) { + WaitHandle.WaitOne(); + } } #if !COMPACTFRAMEWORK @@ -141,6 +143,10 @@ namespace Nuclex.Support.Tracking { /// True if the background process completed, false if the timeout was reached /// public virtual bool Wait(TimeSpan timeout) { + if(this.ended) { + return true; + } + return WaitHandle.WaitOne(timeout, false); } @@ -154,6 +160,10 @@ namespace Nuclex.Support.Tracking { /// True if the background process completed, false if the timeout was reached /// public virtual bool Wait(int timeoutMilliseconds) { + if(this.ended) { + return true; + } + return WaitHandle.WaitOne(timeoutMilliseconds, false); }