Robustly detecting an error when starting an app via code

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

Hi everyone,

Can anyone tell me if there is a standard way of detecting an error in a
process that I've started using the .net framework's
System.Diagnostics.Process class?

I need to regularly call a secondary application but be able to tell if
a problem has occured with it and log the error (and then probably
restart it)

Can anyone tell me how to detect the error in the running process?

Thanks to anyone who can advise

Best regards

Simon
 
Simon,

You can't do this in a generic manner. If anything, you have to have
knowledge of the process and how to retrieve any error that occurs in the
process. The only generic way of handling an error is to use the ExitCode
property on the Process class, but even then, the return values are specific
to the application being run.
 
Nicholas Paldino said:
Simon,

You can't do this in a generic manner. If anything, you have to have
knowledge of the process and how to retrieve any error that occurs in the
process. The only generic way of handling an error is to use the ExitCode
property on the Process class, but even then, the return values are
specific to the application being run.

In addition to the exit code, you can capture output from a console
application, or some programs can be configured to write a log. Another
option might be to start the process under OS debug and capture
OutputDebugString calls (that's what .NET's TraceListener uses to send
messages by default).
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Simon said:
Hi everyone,

Can anyone tell me if there is a standard way of detecting an error in a
process that I've started using the .net framework's
System.Diagnostics.Process class?

I need to regularly call a secondary application but be able to tell if a
problem has occured with it and log the error (and then probably restart
it)

Can anyone tell me how to detect the error in the running process?

Thanks to anyone who can advise

Best regards

Simon
 
Back
Top