简体   繁体   中英

Process.Start() does not work unless stepping over using F10

I would like to start a process using:

ProcessStartInfo createProject = new ProcessStartInfo();
createProject.FileName = exePath;
createProject.UseShellExecute = false;
createProject.WorkingDirectory = projectDirectory;
createProject.Arguments = exeArguments;

try
{
    // Start the process with the info specified.
    System.Diagnostics.Process.Start(createProject);
}
catch (IOException eX)
{
    // Log error.
    MessageBox.Show("Unable to create project", "Error Creating Project");

}

When I put a breakpoint at the line of Process.Start() and continue with step over by pressing F10, then the process runs without any problem.

However when I press F5 at the breakpoint or just run my application without any breakpoints, I get a "Your application has stopped working" dialog, without my application throwing any exception.

I tried also using Thread.Sleep() before the Process.Start() which has no result.

I really wonder what causes this problem.

EDIT: After I check the event viewer, I see that the faulting module is MSVCR90.dll. I have the version 9.0.30729.6161 installed.

This answer is for the one who is interested in the solution of the problem not the pragmatic discussion on the question itself:

Actually the answer was in the question itself and I got it after @rene raised one question.

Process runs when I step over because then program has time to finish its job. But when I press F5 it crashes because the process itself is not completed. I used following code:

ProcessStartInfo createProject = new ProcessStartInfo();
createProject.FileName = exePath;
createProject.UseShellExecute = false;
createProject.WorkingDirectory = projectDirectory;
createProject.Arguments = exeArguments;

try
{
    using (System.Diagnostics.Process exeProcess = System.Diagnostics.Process.Start(createProject ))
          {
             exeProcess.WaitForExit();
          }
}
catch (IOException eX)
{
    // Log error.
    MessageBox.Show("Unable to create project", "Error Creating Project");

}

This is the reason also why it doesn't throw any exception.

Thanks to @rene again!

Check your event log (with eventvwr.exe) to see if the process you're starting is hitting anything critical.

If the started process is also yours, you can add logging to it, or use System.Diagnostics.Debugger.Launch() to have it launch a debugger at startup -- or use gflags to break into it with WinDbg or similar on startup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM