I have this lines of source
for (int i = 0; i < 100; i++)
{
Task.Run(()=> Console.WriteLine(i));
}
I was expecting an output like 0,1,2,3,...,99 , but all I get is 100,100,100,...,100
I am not asking for a solution to get the output I want, all I'm asking is what call is being queued to the Threadpool.
I imagine something like Console.Writeline(reference on i)
is being queued to the Threadpool.
Can someone explained how my code is treated and why?