Launching another Process and knowing if it errors out

I am using the compact framework 1.0 in C#. I am launching another process using the code below. My question is I have noticed if I throw a uncaught exception in the application being launched that the WaitForSingleObject just keeps waiting for the application to close. Is there anyway to know if the process I launched Errors out for any reason

Int32 INFINITE;

unchecked {INFINITE = (int)0xFFFFFFFF;}

if ( pi == null )

pi = new ProcessInfo();

byte [] si = new byte[128];

CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero,

0, 0, IntPtr.Zero, IntPtr.Zero, si, pi);

WaitForSingleObject(pi.hProcess,INFINITE);

return true;



Answer this question

Launching another Process and knowing if it errors out

  • Adrien Regimbald

    You can wrap your entire code in try/catch and watch out for exceptions on the threads.

    NETCF V2 has System. AppDomain.UnhandledException event which could help you out.



  • slein

    Thanks, As far as I know I do handle all exceptions but you never really know of any random place that you thought was perfect that ends up throwing some random exception once in a blue moon.
  • Number10

    Not really, no. The process is stuck not because there was an exception but because it shows dialog about this exception waiting for user input forever. Solution to that issue is rather simple – always handle your exceptions and terminate if you can not recover from them. You can provide error information via exit code as needed.



  • Launching another Process and knowing if it errors out