c# - 为什么 WaitForExit 在我的 C# 代码中不是可用的方法?

标签 c# methods process

下面的代码工作正常,但我需要添加 WaitForExit 方法。但它不显示为可用。我错过了什么?谢谢。

ProcessStartInfo process = new ProcessStartInfo("cmd.exe", @"/C " + AppDomain.CurrentDomain.BaseDirectory + "Setupws.exe");
process.Verb = "runas";
process.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(process);

最佳答案

WaitForExit() 是一个实例方法,它要求您创建一个 Process 的实例并运行它,而不是使用静态的 Process.Start( ) 不捕获 Process 返回值。

一旦创建了 Process 实例并在其上设置了 ProcessStartInfo,就可以调用它的 Start() 实例方法,然后调用 WaitForExit() 在实例上。

ProcessStartInfo info = new ProcessStartInfo();
//Set info properties...
Process process = new Process();
process.StartInfo = info;
//set other process properties...
process.Start();
process.WaitForExit();

关于c# - 为什么 WaitForExit 在我的 C# 代码中不是可用的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13766626/

相关文章:

c# - 在C#方法定义的返回类型前加 'new'?

javascript - 在 javascript 中,如何从同一类中的另一个方法调用类方法?

java - java方法中的数组,执行了什么?

java - 在新进程中启动Java应用程序

process - AMQP 延迟传递和防止重复消息

c# - 有人在任何完整项目中使用过 WebSharper 吗?

c# - 在 Visual Studio 2015 中调试时为 "SignTool.exe not found"

c# - 数据行到 CSV 行 C#

ruby-on-rails - 为什么在保存对象后使用 'reload' 方法? (Hartl Rails Tut 6.30)

java - 基于优先级的线程?