For example, we have two snippets of code:
public static async Task TestAsync() { await Task.Delay(5000); } Task.Run(async () => { for (int i = 0; i < 3; ++i) { await TestAsync(); } }).Wait();
public static void Test() { Task.Delay(5000).Wait(); } Task.Run(() => { for (int i = 0; i < 3; ++i) { Test(); } }).Wait();
(Task.Delay
just represents some long running job.)
Will there be any performance difference between the two snippets of code? (I tested them, and it seems they have same performance.)
But, in theory, will 2) outperform 1) in some situation? (For example, if there are a lot of threads waiting to be executed in the thread pool.)