Console.ReadKey .NET 4.5 changes may deadlock your system

September 12, 2012

I’ve hit a weird issue today. We have a service that we run both as Windows service and from console. A specific use case seemed to cause our system to hang, but only when running from console. Also, I was sure this didn’t happen before I upgraded my machine to .NET 4.5. The service initialization code looks something like this: serviceHost.Open();   while (Console.ReadKey().Key != ConsoleKey.Q) { Console.WriteLine("Press Q to exit"); ...