ReadKey not working in .net core

Found my answer in OmniSharp Visual Code docs: https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window

Console (terminal) window

By default, processes are launched with their console output (stdout/stderr) going to the VS Code Debugger Console. This is useful for executables that take their input from the network, files, etc. But this does NOT work for applications that want to read from the console (ex: Console.ReadLine). For these applications, use a setting such as the following:

"console": "integratedTerminal" When this is set to integratedTerminal the target process will run inside VS Code's integrated terminal. Click the 'Terminal' tab in the tab group beneath the editor to interact with your application.

When this is set to externalTerminal the target process will run in a separate terminal.

I changed this setting in launch.json and now it works


Something that I have used in my own code (which as far as I can see is not mentioned in the linked question) is Console.In which interacts directly with the standard input.
I have tested it in my own project with both Windows CMD and openSUSE KTerm and it works as expected.

My code is specifically:
Console.In.ReadLineAsync().GetAwaiter().GetResult();
because it's in the IO handling BackgroundWorker which is running Async.
Yours may be able to get away with Console.In.ReadKey();, though YMMV as I've not tested anything except ReadLine.

Tags:

C#

.Net Core