0

I have the following code:

var psi = new ProcessStartInfo();

psi.FileName = @"C:\gw\gw.exe";
psi.WorkingDirectory=@"C:\gw";

Process process = Process.Start(psi);

For some reason, the gw.exe process is crashing on startup. Windows just says "This program has been shut down" and has the usual "Looking for a solution online" box and it just crashes.

When I launch gw.exe from Windows explorer, it executes just fine. It is a WPF application and it runs just fine outside of my program. Anyone have any suggestions?

JHobern
  • 866
  • 1
  • 13
  • 20
Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • 2
    Have you checked the windows event logs to see more details about why the application is crashing? – Jason Down Jan 04 '12 at 00:27
  • Have you tried initializing psi.Arguments to something instead of leaving it uninitialized? – Mike Nakis Jan 04 '12 at 00:28
  • Have you tried playing with psi.UseShellExecute ? – Mike Nakis Jan 04 '12 at 00:30
  • @JasonDown - I have looked at the logs, but nothing useful. This is what it shows: Fault Bucket, type 0 Event name CLR20r3 Response not available Cab id:0 – Icemanind Jan 04 '12 at 01:23
  • There are other DLLs this program relys on to run. They are in the same directory as the application. I am setting the WorkingDirectory property. Could this be an issue? – Icemanind Jan 04 '12 at 01:38
  • What if you run this through the debugger or use a try/catch. We need to know what the error is to really address the problem. – Jason Down Jan 04 '12 at 02:31
  • possible duplicate of [Deciphering the .NET clr20r3 exception parameters P1..P10](http://stackoverflow.com/questions/4052770/deciphering-the-net-clr20r3-exception-parameters-p1-p10) – Hans Passant Jan 04 '12 at 10:19

1 Answers1

1

Your code is not how one starts a process:

Console.WriteLine("Running"); 
Process pr = new Process(); 
pr.StartInfo.FileName = "Notepad.exe"; 
pr.StartInfo.Arguments = "test.dat"; 
pr.Start(); 
while (pr.HasExited == false)     
   if ((DateTime.Now.Second % 5) == 0)     
   { 
      // Show a tick every five seconds.         
      Console.Write(".");         
      System.Threading.Thread.Sleep(1000);     
}

I go into further detail in my blog post How to Launch an External Application in C#:

casperOne
  • 73,706
  • 19
  • 184
  • 253
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122