Код: Выделить всё
[Test]
public async Task method1()
{
Task task = run();
await Task.WhenAll(task);
}
[Test]
public async Task method2()
{
Task task = Task.Run(async() =>
{
await run();
});
await Task.WhenAll(task);
}
public async Task run()
{
Console.WriteLine("Current Thread Name: " + Thread.CurrentThread.Name);
// background thread to print numbers with sleep of 1s
await Task.Run(() =>
{
for (int i = 1; i
Подробнее здесь: [url]https://stackoverflow.com/questions/78698959/difference-between-calling-an-async-method-and-wrapping-the-call-in-task-run[/url]