C
C#2y 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;
}
private Process CreateProcess()
{
var process = new Process()
{
StartInfo = new("ScriptingService", _arguments),
EnableRaisingEvents = true,
};
process.Start();
return process;
}
3 Replies
jcotton42
jcotton422y ago
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?
kuba_z2
kuba_z22y ago
oh, so I misunderstood it (actually found a response on StackOverflow 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?
Kai
Kai2y ago
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?
Want results from more Discord servers?
Add your server
More Posts
Top-level statements in MSVSSay you've created a new project with top-level statements in MSVS. Is it possible to change it to *how to format multiple conditions assignments in return statement [CLOSED] [Answered]Greetings, I was wondering, how could I properly format this piece of code. ```cs return res > PagEntity Framework One-To-One [Answered]Code at: https://paste.mod.gg/rccwzntafwoj/0 When attempting to change the database I'm getting: TDatabase - Relationship returns empty set even though records are present [Answered]I think I'm probably missing something stupid obvious... In my batch model, I have ```cs private reaSave storageFile to a folder on driveI have a storagefile ready to give to a control to crop an image the problem is that image crop wilDynamically load .dll into .NET 6 ProgramHi, I've a Blazor WebAssembly Hosted (.NET 6) web application. I've put some part of the applicationMove File To A Matching Type RefactoringWhen everything is top-level do you not need namespaces because everything is "top-level"? Thanks foClass making my program run as a background process after I close it [Answered]https://paste.myst.rs/7o8qz5vk After I close my program through RMB>Close window it continues runniHangfire - Unable to resolve services [Answered]Working with Hangfire. I have a plugin service which has an InitializeAsync method that looks like tASP.NET Website project without namespaces. Converting to ASP.NET Web application.Hi guys, I have a legacy ASP.NET Website project which I want to convert to ASP.NET Website applicat