Oct 12
Most developers use the Process.Start static method to run an external application from within C# code. The Start method launches the external process asynchronously, meaning that your C# code continues executing and does not wait for the process to finish.
But occasionally you may wish to halt your program and wait for the external process to finish. So to launch a process synchronously from a C# application, the key is to create a Process object and call the WaitForExit method after you start the process. Be sure to finish with a call to the process Close method. Here is some sample code:
Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo( "notepad.exe" ); process.StartInfo = startInfo; process.Start(); process.WaitForExit(); process.Close(); MessageBox.Show( "Process Complete" );
Exactly what I needed. Had a component that used 64-bit ADO.NET Jet OleDb Provider, and could not test it under VS 2010 testing tool because the testing environment, being 32-bit code, doesn’t seem to “see” the 64-bit provider – it kept saying “The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine”. So I created a little 64-bit console app that called the component, and used your code to run it and check the results after.
Thanks!