I'm running a series of tasks getting an integer as parameter, but the output is not as expected
static void Main(string[] args) {
var tasks = new List < Task > ();
for (int i = 0; i < 20; i++) {
tasks.Add(new Task(async () => await MeuIp(i)));
}
Parallel.ForEach(tasks, task => {
task.Start();
});
Console.ReadKey();
}
static async Task MeuIp(int i) {
var r = await request.Ip();
Console.WriteLine(i + " " + r);
}
Expected
0 ...
1 ...
2 ...
3 ...
4 ...
5 ...
Actual Output