-2

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.

Lati
  • 341
  • 6
  • 18
  • That depends on what the process is doing and on the values of `exePath`, `projectDirectory` and `exeArguments`. We cannot reproduce this for you. – CodeCaster Oct 21 '15 at 12:27
  • How do you know it's crashed if there is no exception? What do you see? – DavidG Oct 21 '15 at 12:28
  • @CodeCaster This is nothing to do which process I want to start but why same process runs with step over but not normally. I wonder if there is anyone had the same problem. – Lati Oct 21 '15 at 12:29
  • @DavidG Yes, it says the executable stopped working and will be closed. (Why the down-voting for?? It is just because you can down vote?) – Lati Oct 21 '15 at 12:33
  • I think you might need to rephrase this as a question -- perhaps "How do I go about diagnosing what's happening"? – Tim Barrass Oct 21 '15 at 12:33
  • When you say "it crashes", do you mean the executable you start, or the program you wrote? Can you give any information on what program you are starting? What the arguments are? – Ron Beyer Oct 21 '15 at 12:35
  • @RonBeyer I also want to know where it crashes. I only know that it crashes when Process.Start() is called. Wish I could provide anymore information about it but it is a commercial software and I am not able to give any detail. – Lati Oct 21 '15 at 12:38
  • 1
    Note that you are only catching an `IOException` exception so anything else will potentially crash your app. – DavidG Oct 21 '15 at 12:40
  • @DavidG That's an helpful comment finally except coming here just for writing negative comments. I will try it now to get other exceptions as well. By the way I can't know before asking if anyone faced this problem or not so I was not able to formulate a question according to the possible answer. I have a problem, it is real and I explained what it is. – Lati Oct 21 '15 at 12:44
  • If that app is a console app, attach the StdOut and StdErr events as shown in [my answer here](http://stackoverflow.com/a/23921052/578411) and tell us any errors, also catch ALL Exceptions instead of just IO Exception and tell use the exception message and stack trace – rene Oct 21 '15 at 12:44
  • 2
    @Lati all of the previous comments were justified though. If you ask a good and clear question, you will not get things like this happening. We really cannot deduce what is happening by telepathy I'm afraid :) – DavidG Oct 21 '15 at 12:46
  • 1
    And then still, your actual problem is not solved by catching all exceptions. If it works when you step through, but not if you run it without pausing, then for example something in your code is doing that only completes after a while. I want to help you analyze **that**, not mask the actual problem by catching all exceptions. In order to analyze the actual problem, more input from you is required. I don't "come here just for writing negative comments", I come here to help people solve unique problems. For that to work you need to be cooperative. – CodeCaster Oct 21 '15 at 12:49
  • I have tried to make your problem description somewhat clearer. Please edit your question to include what exactly crashes and how: does your application containing the code you show crash, or does the process you try to start crash? And what does "crash" mean exactly? Please note that people don't comment to annoy you, but to help you. Please read [ask]. – CodeCaster Oct 21 '15 at 12:56
  • @DavidG I also can not emphasize what kind of questions make the down voter happy :) Anyway. If you can not help then instead down voting or criticizing the question itself just don't response and ignore. Down votes and that much critics on the question also affects someone who might answer this question. So... – Lati Oct 21 '15 at 12:57
  • Might be related: http://superuser.com/questions/351609/how-can-i-fix-a-missing-msvcr90-dll-file-error – rene Oct 21 '15 at 12:57
  • 1
    @Lati No, if everybody here would do that this site becomes as useless as Yahoo Answers. The post guidelines are not a secret, anyone can find them in the help. Now let's stop arguing and edit the info you left in the comment under the answer to your question and try to get the full stack-trace and exact error and event log messages and add that as well. – rene Oct 21 '15 at 13:02
  • @rene Thanks. Actually I have the MSVCR90.dll version 9.0.30729.6161 installed but maybe there is a problem with version. I will check that. I also tried catching all exceptions catch (Exception eX) instead only IOException but no success. – Lati Oct 21 '15 at 13:02
  • So no exception is raised right? And this all happening on a single thread, right? No background preparations happening that need to finish before you start that exe? – rene Oct 21 '15 at 13:04
  • @rene nope. I am checking if there is an issue with the version – Lati Oct 21 '15 at 13:06
  • You might want to configure [post-mortem-debugging](http://stackoverflow.com/questions/new/postmortem-debugging?show=all&sort=newest&pageSize=50) – rene Oct 21 '15 at 13:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92964/discussion-between-lati-and-rene). – Lati Oct 21 '15 at 13:12

2 Answers2

2

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!

Lati
  • 341
  • 6
  • 18
0

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.

Tim Barrass
  • 4,813
  • 2
  • 29
  • 55
  • 2
    This is not an answer, but a comment. – CodeCaster Oct 21 '15 at 12:33
  • So if I phrased it as "yes, I've had this problem -- and these are the techiques I used to solve it" would that be better? – Tim Barrass Oct 21 '15 at 12:35
  • 1
    @TimBarrass It seems there is a problem with the MSVCR90.dll according to the event viewer. Process I want to start is not mine and I have only executable. – Lati Oct 21 '15 at 12:51