Is there a way to poke the [enter] keystroke into the current process, to force the thread blocking on Console.ReadLine() to exit?
More Info (you can ignore this)
I have a C# console app which is running another thread which is blocking on Console.ReadLine(). As Console.ReadLine calls a native windows thread that runs deep in the bowels of unmanaged code within Windows, it won’t abort until it unblocks, and that won’t happen until it receives a keypress on the keyboard.
Thus, when I call “.Abort” on this thread, within C# .NET, it won’t about until I manually press [enter] on the console. I want to automate this keypress.
Use PostMessage to send [enter] into the current process:
This answer also works around the fact that calling
.AbortonReadLine()won’t work in C#, asReadLine()is running in unmanaged code deep within the Windows kernel.This answer is superior to any answers that only work if the current process has the focus, such as SendKeys and Input Simulator.