Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Task SomeAsyncMethod()
- {
- var tcs = new TaskCompletionSource();
- ... do something, NOT setting the TaskCompletionSource...
- return tcs.Task
- }
- public void Callsite1()
- {
- await SomeAsyncMethod();
- Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
- }
- public void Callsite2()
- {
- SomeAsyncMethod().ContinueWith((task) =>
- {
- Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
- });
- }
- Debug.WriteLine(Thread.CurrentThread.ManagedThreadId);
- tcs.SetResult();
- public void Callsite1()
- {
- await SomeAsyncMethod().ConfigureAwait(true or false);
- }
- // Set the result on a threadpool thread, so any synchronous continuations
- // will execute in the background.
- Task.Run(() => tcs.TrySetResult(result));
- // Wait for the TCS task to complete; note that the continuations
- // may not be complete.
- tcs.Task.Wait();
- public static void TrySetResultWithBackgroundContinuations<TResult>(
- this TaskCompletionSource<TResult> @this, TResult result);
Add Comment
Please, Sign In to add comment