Leo.1906 Leo.1906 - 1 year ago 154
C# Question

C# wait for external PID to exit

How do I wait until PID (not started from program itself) doesn't exist any longer?
I want my program to get a PID from an external program via commandline parameter and just wait for it to exit and then do something.

I searched for it, but all I could find were examples where the process has been startet by the C# program itself. That's easy to manage ..

I was going with something like this, but it obviously doesn't work ..

Process[] pname = Process.GetProcessById(7860);
if (pname.Length == 0)

How can that be accomplished?

Answer Source

You can do that easily by writing:

var p = Process.GetProcessById(7860);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download