Skip to content

Commit 9f3c54e

Browse files
Copilotgewarren
andauthored
Fix Windows process group example: CTRL_BREAK_EVENT, not CTRL_C_EVENT (#53564)
* Initial plan * Fix ProcessGroup example: use CTRL_BREAK_EVENT instead of CTRL_C_EVENT for process groups Agent-Logs-Url: https://github.com/dotnet/docs/sessions/f36bbc2c-5f0f-4b18-a5de-6f801890df6d Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
1 parent 4052c9e commit 9f3c54e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

docs/core/whats-new/dotnet-10/snippets/csharp/ProcessGroup.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,27 @@ static void Main(string[] args)
2121
using Process process = Process.Start(psi)!;
2222
Thread.Sleep(5_000);
2323

24-
GenerateConsoleCtrlEvent(CTRL_C_EVENT, (uint)process.Id);
24+
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, (uint)process.Id);
2525
process.WaitForExit();
2626

2727
Console.WriteLine("Child process terminated gracefully, continue with the parent process logic if needed.");
2828
}
2929
else
3030
{
31-
// If you need to send a CTRL+C, the child process needs to re-enable CTRL+C handling, if you own the code, you can call SetConsoleCtrlHandler(NULL, FALSE).
31+
// CREATE_NEW_PROCESS_GROUP disables CTRL+C handling in the new process group.
32+
// CTRL+BREAK is not affected, so you don't need to re-enable it with SetConsoleCtrlHandler.
33+
// If you use CTRL+C instead, re-enable handling by calling SetConsoleCtrlHandler(NULL, FALSE).
3234
// see https://learn.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#remarks
33-
SetConsoleCtrlHandler((IntPtr)null, false);
3435

3536
Console.WriteLine("Greetings from the child process! I need to be gracefully terminated, send me a signal!");
3637

3738
bool stop = false;
3839

39-
var registration = PosixSignalRegistration.Create(PosixSignal.SIGINT, ctx =>
40+
var registration = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, ctx =>
4041
{
4142
stop = true;
4243
ctx.Cancel = true;
43-
Console.WriteLine("Received CTRL+C, stopping...");
44+
Console.WriteLine("Received CTRL+BREAK, stopping...");
4445
});
4546

4647
StreamWriter sw = File.AppendText("log.txt");

0 commit comments

Comments
 (0)