public static void WatchProcess (string procId)
{
int id = int.Parse (procId);
var t = new Thread (delegate () {
while (true) {
Thread.Sleep (1000);
try {
// Throws exception if process is not running.
// When watching a .NET process from Mono, GetProcessById may
// return the process with HasExited=true
Process p = Process.GetProcessById (id);
if (p.HasExited)
break;
}
catch {
break;
}
}
exitEvent.Set ();
});
t.IsBackground = true;
t.Start ();
}
}