当前位置: 移动技术网 > IT编程>开发语言>c# > C#启动进程的几种常用方法

C#启动进程的几种常用方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例讲述了c#启动进程的几种常用方法。分享给大家供大家参考。具体如下: 1.启动子进程,不等待子进程结束 private void simplerun_cl

本文实例讲述了c#启动进程的几种常用方法。分享给大家供大家参考。具体如下:

1.启动子进程,不等待子进程结束

private void simplerun_click(object sender, system.eventargs e)
{
 system.diagnostics.process.start(@"c:\listfiles.bat");
}

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;
  }
}

3.使用默认的浏览器打开url

private void launchurl_click(object sender, system.eventargs e)
{
  string targeturl = @//www.jb51.net;
  system.diagnostics.process.start(targeturl);
}

希望本文所述对大家的c#程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网