开发者

C# Program Exits After Running Other Process

This problem is bizarre. I have never encountered anything like it before. I am trying to make my program extract a file using 7zip. I have done this before in other programs and it was never too difficult. So I copy and pasted my code in:

Process process = new Process
{
    StartInfo =
    {
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden,
        FileName = "7za.exe",
        UseShellExecute = false,
        ErrorDialog = false,
        Arguments = "x -y -o\"" + outputPath +"\" \""+ inputFile +"\"",
        RedirectStandardOutput = false,
    }
};
process.Start();

Immediately after this code has run my application terminates. It just disappears. It's certainly not meant to! I used the step into function and ran it. As soon as process.Start(); had finished the program closed and returned me into Visual C#. It didn't run any Application.Exit(); or anything, it just went away. There was no error awaiting me in Visual C#. So I tried adding a MessageBox.Show("Test"); to the end. Ran it in step mode. Did process.Start(); f开发者_开发知识库ine, as soon as it executed the MessageBox code it disappeared again. I didn't even click ok in the message box (which showed up for about 0.2 seconds before the application terminated)


Well if this code is in Main() then it will finish when your code is done executing. Can you post the full code where this snippet is contained?

You can wait for the process to finish by including

process.WaitForExit();

Checking the ExitCode might tell you if your process succeeded. And you can always redirect the StandardError to check the output of that too.

process.StartInfo.RedirectStandardError = true;
string error = process.StandardError.ReadToEnd();


Try process.WaitForExit() after process.Start() ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜