C# プロセスの終了を待つには?
プロセスの終了を待つには WaitForExit メソッドが使えます。コードは同期的にプロセスの終了を待ち、その後で実行を再開します。例を見てみましょう。上のコードは新しい cmd.exe プロセスを開始し、timeout 5 コマンドを実行します。process.WaitForExit() の呼び出しによって、プログラムは...
プロセスの終了を待つには WaitForExit メソッドが使えます。コードは同期的にプロセスの終了を待ち、その後で実行を再開します。
例を見てみましょう。
var process = new Process
{
StartInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/C timeout 5"
}
};
process.Start();
process.WaitForExit();
上のコードは新しい cmd.exe プロセスを開始し、timeout 5 コマンドを実行します。process.WaitForExit() の呼び出しによって、プログラムは timeout コマンドの実行が終わるまで待機します。その後、スレッドの実行が再開されます。
Comments
Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.