throw new ArgumentOutOfRangeException ("creationOptions");
var tcs = new TaskCompletionSource<TResult> (state, creationOptions);
- beginMethod (l => InnerInvoke (tcs, endMethod, l), state);
+ var iar = beginMethod (l => InnerInvoke (tcs, endMethod, l), state);
+ if (iar != null && iar.CompletedSynchronously) {
+ InnerInvoke (tcs, endMethod, iar);
+ }
return tcs.Task;
}
throw new ArgumentOutOfRangeException ("creationOptions");
var tcs = new TaskCompletionSource<TResult> (state, creationOptions);
- beginMethod (arg1, l => InnerInvoke (tcs, endMethod, l), state);
+ var iar = beginMethod (arg1, l => InnerInvoke (tcs, endMethod, l), state);
+ if (iar != null && iar.CompletedSynchronously) {
+ InnerInvoke (tcs, endMethod, iar);
+ }
return tcs.Task;
}
throw new ArgumentOutOfRangeException ("creationOptions");
var tcs = new TaskCompletionSource<TResult> (state, creationOptions);
- beginMethod (arg1, arg2, l => InnerInvoke (tcs, endMethod, l), state);
+ var iar = beginMethod (arg1, arg2, l => InnerInvoke (tcs, endMethod, l), state);
+ if (iar != null && iar.CompletedSynchronously) {
+ InnerInvoke (tcs, endMethod, iar);
+ }
return tcs.Task;
}
throw new ArgumentOutOfRangeException ("creationOptions");
var tcs = new TaskCompletionSource<TResult> (state, creationOptions);
- beginMethod (arg1, arg2, arg3, l => InnerInvoke (tcs, endMethod, l), state);
+ var iar = beginMethod (arg1, arg2, arg3, l => InnerInvoke (tcs, endMethod, l), state);
+ if (iar != null && iar.CompletedSynchronously) {
+ InnerInvoke (tcs, endMethod, iar);
+ }
return tcs.Task;
}
}
}
+ class TestAsyncResultCompletedSynchronously : IAsyncResult
+ {
+ public object AsyncState {
+ get {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public WaitHandle AsyncWaitHandle {
+ get {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public bool CompletedSynchronously {
+ get {
+ return true;
+ }
+ }
+
+ public bool IsCompleted {
+ get {
+ throw new NotImplementedException ();
+ }
+ }
+ }
+
+
[SetUp]
public void Setup ()
{
Assert.IsTrue (task.Wait (1000), "#1");
Assert.AreEqual (5, task.Result, "#2");
}
+
+ IAsyncResult BeginGetTestAsyncResultCompletedSynchronously (AsyncCallback cb, object obj)
+ {
+ return new TestAsyncResultCompletedSynchronously ();
+ }
+
+ string EndGetTestAsyncResultCompletedSynchronously (IAsyncResult res)
+ {
+ return "1";
+ }
+
+ [Test]
+ public void FromAsync_CompletedSynchronously ()
+ {
+ var factory = new TaskFactory<string> ();
+ var task = factory.FromAsync (BeginGetTestAsyncResultCompletedSynchronously, EndGetTestAsyncResultCompletedSynchronously, null);
+
+ Assert.IsTrue (task.Wait (1000), "#1");
+ Assert.AreEqual ("1", task.Result, "#2");
+ }
}
}