我如何从C#开始一个过程? [英] How do I start a process from C#?

查看:85
本文介绍了我如何从C#开始一个过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启动过程,例如当用户单击按钮时启动URL?

How do I start a process, such as launching a URL when the user clicks a button?

推荐答案

马特·汉密尔顿(Matt Hamilton)是一种对过程有有限控制的快速方法,是在System.Diagnostics.Process类上使用静态Start方法。

As suggested by Matt Hamilton, the quick approach where you have limited control over the process, is to use the static Start method on the System.Diagnostics.Process class...

using System.Diagnostics;
...
Process.Start("process.exe");

另一种方法是使用Process类的实例。这样可以对过程进行更多控制,包括调度,运行窗口的类型以及对我来说最有用的等待过程完成的能力。

The alternative is to use an instance of the Process class. This allows much more control over the process including scheduling, the type of the window it will run in and, most usefully for me, the ability to wait for the process to finish.

using System.Diagnostics;
...
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "process.exe";
process.StartInfo.Arguments = "-n";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
process.WaitForExit();// Waits here for the process to exit.

此方法比我之前提到的要多得多的控制权。

This method allows far more control than I've mentioned.

这篇关于我如何从C#开始一个过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆