Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for #162

  • Loading branch information...
commit 4553d5d92a46e9ee420d1823cacdeacfac3ad8d0 1 parent 89d18c3
@garuma garuma authored
View
2  mcs/class/corlib/System.Threading.Tasks/Task.cs
@@ -121,7 +121,7 @@ public Task (Action<object> action, object state, CancellationToken cancellation
this.action = action;
this.state = state;
this.taskId = Interlocked.Increment (ref id);
- this.status = TaskStatus.Created;
+ this.status = cancellationToken.IsCancellationRequested ? TaskStatus.Canceled : TaskStatus.Created;
this.token = cancellationToken;
this.parent = parent;
View
9 mcs/class/corlib/Test/System.Threading.Tasks/TaskTest.cs
@@ -117,6 +117,15 @@ public void CancelTestCase()
Assert.AreEqual (1, aggr.InnerExceptions.Count, "#4");
Assert.IsInstanceOfType (typeof (OperationCanceledException), aggr.InnerExceptions[0], "#5");
}
+
+ [Test, ExpectedException (typeof (InvalidOperationException))]
+ public void CreationWhileInitiallyCanceled ()
+ {
+ var token = new CancellationToken (true);
+ var task = new Task (() => { }, token);
+ Assert.AreEqual (TaskStatus.Canceled, task.Status);
+ task.Start ();
+ }
[Test]
public void ContinueWithOnAnyTestCase()
Please sign in to comment.
Something went wrong with that request. Please try again.