why this method doesn't output anything? I did the same thing with the threads and it worked but this way doesn't wok. Do am I missing something?
C#
foreach(var i in arr)
await Task.Run(() => {
Task.Delay(i * 100);
Console.WriteLine(i);
});
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Sep 23, 2022, 9:21 AM EDT
Use Parallel.Foreach
Vishal JoshiRank #377 · 6.7K reputationPosted Sep 23, 2022, 2:02 AM EDT
Hello
You need to add wait at the end. please find below the code for the sample.
foreach (var i in arr) { Task.Run(() => { Task.Delay(i * 100); Console.WriteLine(i); }).Wait(); }