Process Management in .NET.

In my Server / Client setup, I have client applications that control other applications on the computer (start / stop / reboot / request processes). Right now, I just have a very simple setup using the process ID, but it happened to me before it starts living, I need to improve this.

If the process stops and the other starts to use the same identifier between the moments when I issue a request for it, this will lead to the removal of the system. None of the processes that I start will ever come from the same file path, but often will have the same executable file name.

I was not very lucky to find it, but can I find an executable path for a working service? I believe that the best option when querying the current state would be to first look for the stored identifier of the process on which it should be, if it is running, check the file name / executable name to make sure it also matches.

Would there be a better way to do this, or is this the best possible scenario?

+4
source share
1 answer

You can use the Process.Exited event to receive notifications of the completion of a process that you control. Thus, there will be no chance that what happens is "until you look."

Note: for an Exited event to be raised, you must first explicitly set Process.EnableRaisingEvents to true .

+4
source

Source: https://habr.com/ru/post/1343313/


All Articles