Permalink
Browse files

Fix for #162

  • Loading branch information...
1 parent 89d18c3 commit 4553d5d92a46e9ee420d1823cacdeacfac3ad8d0 @garuma garuma committed Aug 5, 2011
@@ -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;
@@ -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()

0 comments on commit 4553d5d

Please sign in to comment.