I am creating a windowservice that starts a process where I pass multiple cmd arguments in the StartInfo.Arguments. That works fine as expected.
The problem is that when i stop the windowsservice, I need to tell the running program to shut down gracefully before the windows service stops. Because if I just kill the process the program does not save the collected data. The program that I run is the Process Monitor and it accepts the following command "/terminate".
How can I pass the /terminate argument before my windows service stops?
There is a couple of ways you can approach this solution but you can signal the process, and based on what you send with this signal it should execute its 'clean-up' code. Once it's finished, the process that spawned it should be signalled that it finished the cleanup code and can then shutdown. This of course assumes that you wrote the code for both the Window service and the process being spawned.
You can try Named pipes (https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-use-named-pipes-for-network-interprocess-communication)