I have a small .NET console program that asks for SQL credentials (login, password). The problem is that if I key Ctrl-C during login prompt (string userId = Console.ReadLine();
below), the program stops but "password:"
prompt is written to the console. Relevant fragment:
Console.Write("login: ");
string userId = Console.ReadLine();
Console.Write("password: ");
Output on Ctrl-C during login prompt:
login: password:
How can I avoid executing subsequent the Console.Write("password: ");
after exiting with Ctrl-C?
UPDATE 1: CancelKeyPress event handler doesn't help. At least for me, it works for Console.ReadKey, but not for Console.ReadLine: password prompt is still written.
UPDATE 2: If there is Write/WriteLine after null-check block, it's still executed on my machine (Win10, VS2019). So, the question in fact remains. Current workaround - ReadKey.