Possible Duplicate:
How to know if Process.Start() is successful?
I have a process similar to a watchdog(let's call it WD) in my program which is another running process(let's call it A). I am starting WD process at a certain event, let's say a key is pressed and I want to start another process with this process, let's call it B.
The thing is that I want to shut down the initial process A after what I know that process B was successfully started. How can I check that?
I am starting process WD and B with Process.Start(argList) and ProcessInfo(argList) syntax.
Each process is a simple C# Console Application.
Process.Start returns a boolean (true if process started correctly) Check this MSDN link for Process.Start() method.
Your code should be something like:
Process B= new Process();
try
{
B.StartInfo.UseShellExecute = false;
B.StartInfo.FileName = "C:\\B.exe";
B.StartInfo.CreateNoWindow = true;
if (B.Start())
{
// Kill process A
}
else
{
// Handle incorrect start of process B and do NOT stop A
}
}
catch (Exception e)
{
// Handle exception and do NOT stop A
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With