C#C
C#4y ago
Kuba_Z2

Process.EnableRaisingEvents does not work on Windows

I have an app that have 20 workers that are other processes. On production, on ubuntu, when I close the main process with ^C, the workers die as they should, but on Windows, when I kill the process, the workers still exist and use 100% of my i9-12900k (lol), it's because the workers have endless loops and throw exceptions in them when there is no main process. When I close app console window, the main process and workers are not closed and when I kill the main process, I have 100% of cpu usage. Did I miss something?
I use this method to create a worker:
        private Process CreateProcess()
        {
            var process = new Process()
            {
                StartInfo = new("ScriptingService", _arguments),
                EnableRaisingEvents = true,
            };
            process.Start();
            return process;
        }
Was this page helpful?