I have a program that starts a few subprocesses (ProcessStartInfo, Process combo).
The parent application is listening for the cancel key in it's Main function:
Console.CancelKeyPress += (s, ev) =>
{
// do stuff on Ctrl + C
};
This gets in invoked on the proper key press and all is fine and dandy. The subprocess I start however ALSO are subscribed to Console.CancelKeyPress and they are triggered as well even though when I start them I have their RedirectStandardInput = true set.
So it seems that I have misunderstood something, or that Console.CancelKeyPress is not considered standard input and is instead something special.
I have a specific shutdown sequence I want to employ, and my intention is to shut down the subprocesses when it's appropriate, but because they also receive the Console.CancelKeyPress it makes it impossible to direct them when the right time is to shut down.
Now granted, I could just edit their source and disable that or add some flags to their startup to not subscribe to Console.CancelKeyPress but I am wondering if I am just missing something here as it seems this should not be required, especially I am redirecting the standard input of the subprocess.
I found this somewhat related question: https://stackoverflow.com/a/1802908/1060314
The author states:
My understanding is that when you press CTRL+C in a console, by default all the processes attached to the console receive it, not just the parent one.