假设我有以下代码:public async void Run(){ TaskCompletionSource t = new TaskCompletionSource(); Prepare(t.Task); await Task.Delay(1000); t.SetResult(); Console.
假设我有这样的代码:
public async void Run()
{
TaskCompletionSource t = new TaskCompletionSource();
Prepare(t.Task);
await Task.Delay(1000);
t.SetResult();
Console.WriteLine("End");
}
public async void Prepare(Task task)
{
await Run(task, "A");
await Run(task, "B");
await Run(task, "C");
await Run(task, "D");
}
public async Task Run(Task requisite, string text)
{
await requisite;
Console.WriteLine(text);
}
时会发生什么 t.SetResult();
?这是多线程吗?控制台中项目的顺序有任何保证吗?如果我有一个 List<>
,并且该 Run
方法会改变它,我需要担心多线程吗?