throw new ArgumentOutOfRangeException ("creationOptions");
var tcs = new TaskCompletionSource<TResult> (state, creationOptions);
- beginMethod (l => InnerInvoke (tcs, endMethod, l), state);
+ var alreadyInvoked = new AtomicBoolean ();
+ var iar = beginMethod (l => {
+ if (alreadyInvoked.TryRelaxedSet ())
+ InnerInvoke (tcs, endMethod, l);
+ }, state);
+ if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ())
+ 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 alreadyInvoked = new AtomicBoolean ();
+ var iar = beginMethod (arg1, l => {
+ if (alreadyInvoked.TryRelaxedSet ())
+ InnerInvoke (tcs, endMethod, l);
+ }, state);
+ if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ())
+ 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 alreadyInvoked = new AtomicBoolean ();
+ var iar = beginMethod (arg1, arg2, l => {
+ if (alreadyInvoked.TryRelaxedSet ())
+ InnerInvoke (tcs, endMethod, l);
+ }, state);
+ if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ())
+ 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 alreadyInvoked = new AtomicBoolean ();
+ var iar = beginMethod (arg1, arg2, arg3, l => {
+ if (alreadyInvoked.TryRelaxedSet ())
+ InnerInvoke (tcs, endMethod, l);
+ }, state);
+ if (iar != null && iar.CompletedSynchronously && alreadyInvoked.TryRelaxedSet ())
+ InnerInvoke (tcs, endMethod, iar);
return tcs.Task;
}