sti*_*til 1 c# multithreading async-await
考虑以下伪代码:
线 #1
var task = new Task<int>();
this.AwaitingTask = task;
return await task;
Run Code Online (Sandbox Code Playgroud)
线 #2
this.AwaitingTask.Complete(16);
Run Code Online (Sandbox Code Playgroud)
这样,#2线程将传递返回值(int)并通知Task已完成.所以#1线程会知道继续执行.
有可能实施吗?如何?我正在寻找能以类似方式工作的最接近的想法.
您不必实现它.它已经附带名称 
TaskCompletionSource<T>
线程1
var completionSource = new TaskCompletionSource<int>();
this.CompletionSource= completionSource;
return await completionSource.Task;
Run Code Online (Sandbox Code Playgroud)
线程2
this.CompletionSource.SetResult(16);
Run Code Online (Sandbox Code Playgroud)