Replies: 1 comment 1 reply
-
Hi there.
What exactly is not scaling well in your implementation? Event registrations? Instead of binding a new event handler each time a process runs, why not have a global CTS that you bind to once? Overall, the approach you have seems reasonable to me. If you're on Windows, the most optimal way, however, is to create a Process Job with mutual termination and add the spawned process to it. Here's an example implementation: This will guarantee that all processes within a job will be terminated at an operating system level, although there's a potential race condition between the sub process start and it being assigned to a job. There might be something similar for other systems, but I'm primarily a Windows user so I'm not aware of them. |
Beta Was this translation helpful? Give feedback.
-
Hello,
How to ensure the lifetime of the child process does not extend beyond the lifetime of the parent process?
This is regarding keeping a process running only for the lifetime of the application, I'm curious how can I terminate an ongoing process once my application exists in an elegant way.
Currently, I'm just calling the cancelation token on exit, but it's not scaling very well as the number of processes I run increases.
Currently, I'm thinking of adding an extension method that ensures that the lifetime is within the life of the parent process.
something like this
Right now I'm thinking the basic implementation would be something like
This is just a naive draft implementation it will probably be more robust later on.
So I would like to ask for opinions on this approach and any alternative ways of doing this.
Beta Was this translation helpful? Give feedback.
All reactions