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:
3 Replies
The EnableRaisingEvents property is used in asynchronous processing to notify your application that a process has exited.this just allows the parent to know when the child has exited how are the child processes told to exit?
oh, so I misunderstood it (actually found a response on that told
EnableRaisingEvents
makes process die after main process is closed some time ago). Is there any easy way to make child processes die after main process is closed?I don't think so, you could automatically do this when you close though, on winforms/WPF you get an event. In a console app you'd have to somehow put a big try-catch around everything at the end +
AppDomain.CurrentDomain.UnhandledException
and kill all child processes that way?