假设以下虚构(和无用)方法:
public async Task SomethingAsync()
{
await SomeAsyncOperation();
}
public async Task Execute(int numOfTimes)
{
var tasks = new List<Task>();
for (var i = 0; i < numOfTimes; i++)
{
// how does this...
var task = Task.Run(async () => await SomethingAsync());
// differ to the line below? (i.e. no async/await in Task.Run)
// var task = Task.Run(() => SomethingAsync());
tasks.Add(task);
}
await Task.WhenAll(tasks);
}
public async Task Test()
{
await Execute(10);
}
async/await
中是否存在Task.Run()
个关键字会如何影响相关任务?
我在SO上发现了一个类似的问题,然而.Result
编写了这个任务,这是我没有做的事情。