欧阳不疯 通过本文主要向大家介绍了c#启动进程,c#关闭进程,c#结束进程,c#判断进程是否存在,c#获取进程等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了C#启动进程的几种常用方法。分享给大家供大家参考。具体如下:
1.启动子进程,不等待子进程结束
private void simpleRun_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start(@"C:\listfiles.bat");
}
</div>
2.启动子进程,等待子进程结束,并获得输出
private void runSyncAndGetResults_Click(object sender,System.EventArgs e)
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = listFiles.StandardOutput;
listFiles.WaitForExit(2000);
if (listFiles.HasExited)
{
string output = myOutput.ReadToEnd();
this.processResults.Text = output;
}
}
</div>
3.使用默认的浏览器打开URL
private void launchURL_Click(object sender, System.EventArgs e)
{
string targetURL = @http://www.weikejianghu.com;
System.Diagnostics.Process.Start(targetURL);
}
</div>
希望本文所述对大家的C#程序设计有所帮助。
</div>
