0

I have a C# Windows service that creates subprocesses. How can I stop those subprocesses gracefully from my Windows service? I have tried lot of ways without success.

The main process is starting the sub process who is starting a video recording session. At some point the main process need to notify the sub process to stop recording. This has to be done by gracefully closing the sub process (or sending ctrl-c). I am able to achieve this in a console app but not a windows service. Also, I do not control that sub process, it's an executable from a 3rd party.

The sub process must close gracefully since it needs to save document, terminate the process is not an option.

d219
  • 2,707
  • 5
  • 31
  • 36
Hockeymtl
  • 1
  • 2
  • Send the close message. It's possible with the win api, not sure if there is a library around for .net. https://stackoverflow.com/questions/5402158/using-sendmessage-to-send-wm-close-to-another-process#8813732 – Stefan Jun 19 '19 at 20:47
  • Why can't the sub-processes not simply exit after saving the document? What are those sub-processes anyway? Without knowing details of the involved programs it is difficult to say anything else than "_kill them sub processes_"... –  Jun 19 '19 at 20:52
  • There is a Process.Exited eventhandler in c# where you can wrap up your work before full exit. Have you explored this option? – Travis Acton Jun 19 '19 at 20:55
  • Elgonzo The main process is starting the sub process how is startung a video recording session. At some point in time later on, the main process need to notify the sub process to stop recording. This has to be done by gracefully closing the sub process (or sending ctrl-c). I am able to achieve this in a console app that is not a windows service. Also, i do not control that sub process, it's an executable from a 3rd party. – Hockeymtl Jun 19 '19 at 21:00
  • Travis acton i do not control the sub process, it's an executable from a 3rd party. – Hockeymtl Jun 19 '19 at 21:02
  • It'll be helpful if you show your code so people can get a better understanding of what you mean. – Sach Jun 19 '19 at 21:07
  • https://stackoverflow.com/a/514801/9494461 This has already been solved, Google is your friend! – Will Hatch Jun 19 '19 at 22:14

0 Answers0