如何开始从C#的过程? [英] How to start a process from C#?

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

问题描述

如何启动一个进程,比如当用户点击一个按钮,启动一个URL?

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

推荐答案

的建议由马特·汉密尔顿,快捷的办法,你只有有限的控制权的过程中,是使用静态Start方法上的System.Diagnostics.Process类...

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天全站免登陆