Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parallel.For and async
Starting
Starting 0
Starting 4
Starting 3
Starting 8
Starting 7
Starting 6
Starting 2
Starting 1
Starting 5
Starting 9
Ending
Press any key to continue . . .
using System;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting");
Parallel.For(0, 10, async (i) =>
{
Console.WriteLine("Starting " + i);
await Task.Delay(TimeSpan.FromSeconds(10));
Console.WriteLine("Ending " + i);
});
Console.WriteLine("Ending");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment