I\'m getting a weird problem when using Console.ReadKey() in a multithreaded program.
My question is: Why is this happening? Is it a bug, or is it becau
This is a race condition. Here is what's happening when the first Console.WriteLine is not there:
The reason it behaves differently when the Console.WriteLine is left in there is because the call to Console.InitializeStdOutError is not happening in parallel with Console.ReadKey.
So the short answer is: yes you are abusing Console. You could either initialize the console yourself (by dereferencing Console.Out), or you would wait on an event after starting the Task, but before ReadKey, and then have the Task signal the event after calling Console.WriteLine the first time.