1

C# プロジェクトで別の exe のコンソールを 1 行ずつ読んでいます。プロジェクトは各コンソール行を正常に読み取りますが、直面している問題は、exe が実行を開始したときに c# フォームがハングし、外部 exe が完全に実行されなくなるまで待機することです。 .

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.FileName = EXELOCATION;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = argv;
startInfo.RedirectStandardOutput = true;
try
{
    // Start the process with the info we specified.
    // Call WaitForExit and then the using statement will close.
    using (exeProcess = Process.Start(startInfo))
    {
        using (StreamReader reader = exeProcess.StandardOutput)
        {
            string result;
            while ((result = reader.ReadLine() ) != null)
            {                            
                scanning.Text = result;
                scanning.Refresh();
                Console.Write(result);
            }
        }

    }

この問題にどのように取り組むべきですか、親切に私を導いてください

4

4 に答える 4

0

スレッドについて学ぶことをお勧めします。開始するための最良かつ最も簡単な方法は、 Winforms のバックグラウンド ワーカークラスです。

ただし、System.Threading名前空間も確認する必要があります。

于 2013-10-08T11:02:40.987 に答える