Explorar el Código

Also check directly Task.IsCompleted when we are waiting

Jérémie Laval hace 15 años
padre
commit
bb29e352e0

+ 5 - 2
mcs/class/corlib/System.Threading.Tasks/Scheduler.cs

@@ -66,7 +66,7 @@ namespace System.Threading.Tasks
 
 			ManualResetEventSlim evt = new ManualResetEventSlim (false);
 			task.ContinueWith (_ => evt.Set (), TaskContinuationOptions.ExecuteSynchronously);
-			if (evt.IsSet)
+			if (evt.IsSet || task.IsCompleted)
 				return;
 			
 			ParticipateUntilInternal (task, evt, -1);
@@ -79,9 +79,12 @@ namespace System.Threading.Tasks
 
 			bool isFromPredicate = true;
 			task.ContinueWith (_ => { isFromPredicate = false; evt.Set (); }, TaskContinuationOptions.ExecuteSynchronously);
-			
+
 			ParticipateUntilInternal (task, evt, millisecondsTimeout);
 
+			if (task.IsCompleted)
+				return false;
+
 			return isFromPredicate;
 		}
 		

+ 1 - 1
mcs/class/corlib/System.Threading.Tasks/ThreadWorker.cs

@@ -254,7 +254,7 @@ namespace System.Threading.Tasks
 			bool hasAutoReference = autoReference != null;
 			Action<Task> adder = null;
 
-			while (!predicateEvt.IsSet && watch.ElapsedMilliseconds < millisecondsTimeout) {
+			while (!predicateEvt.IsSet && watch.ElapsedMilliseconds < millisecondsTimeout && !self.IsCompleted) {
 				// We try to execute the self task as it may be the simplest way to unlock
 				// the situation
 				if (self.Status == TaskStatus.WaitingToRun) {