In my application the user can start a visual studio code process by clicking a button (its getting disabled after clicking). Now I want to detect, when its getting closed by the Exited
-event. Before starting the process I have to check if there is already an instance running because then I have to subscribe the running process to the Exited
-event (if I subscribe my new process to it, it will be triggered instantly).
The problem is, if you start one instance of VS code there are 5 'subprocesses', so I have to detect if they are all closed before I can enable the button again. After the Exited
-event not all processes are finished instantly.
One solution was Thread.Sleep(500)
but its not a good way to solve it in my opinion.
Is there another solution?
EDIT: The main task is to detect if the process is on its way to shut down.