我開始使用parameteres創建應用程序,並且我想在「Startup.exe」關閉後關閉我的C#應用程序。 startup.exe關閉C#應用程序仍在運行後,所以我的問題是爲什麼WaitForExit()不適合我?以及如何解決這個問題?C#WaitForExit()不工作?
private void button4_Click(object sender, EventArgs e)
{
string arg0 = "/connect";
string arg1 = txtUsername.Text;
string arg2 = txtPassword.Text;
string genArgs = arg0+" "+arg1 +" "+ arg2;
string pathToFile = System.IO.Directory.GetCurrentDirectory()+"/Startup.exe";
Process runProg = new Process();
runProg.StartInfo.FileName = pathToFile;
runProg.StartInfo.Arguments = genArgs;
runProg.Start();
runProg.WaitForExit();
}
你期望'runProg.WaitForExit()'做什麼?提示:它不會關閉你的應用程序。檢查[MSDN](https://msdn.microsoft.com/library/system.diagnostics.process.waitforexit(v = vs.110).aspx) –
您可能想查看[如何正確退出C#應用程序] (http://stackoverflow.com/questions/12977924/how-to-properly-exit-ac-sharp-application) –