I have a console application,when I use Console.ReadLine(),the application will show "Hello World".why Console.ReadKey() can't?`
static void Main(string[] args)
{
System.Timers.Timer timer = new System.Timers.Timer(1000);
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
Console.ReadKey();// When use ReadLine() work fine;
}
static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("Hello World");
}
Fixed:http://support.microsoft.com/kb/2805221
Console.ReadKey .NET 4.5 changes may deadlock your system
Console.ReadKey now locks a synchronization object which gets locked when you attempt to access stderr for the first time. Therefore, the solution is simple, we need to cause Console.Error to initialize before the call to Console.ReadKey.
update:An update is available for the .NET Framework 4.5 in Windows 7 SP1, Windows Server 2008 R2 SP1, Windows Server 2008 SP2, and Windows Vista SP2: May 2013
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With