熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C# 中啟動進程的三種方法

2013-11-13 10:28:05  來源: .NET編程 
啟動子進程不等待子進程結束

  private void simpleRun_Click(object sender SystemEventArgs e)
{ SystemDiagnosticsProcessStart(@C:listfilesbat);
}
啟動子進程等待子進程結束並獲得輸出

  private void runSyncAndGetResults_Click(object sender SystemEventArgs e)
{
  SystemDiagnosticsProcessStartInfo psi = new SystemDiagnosticsProcessStartInfo(@C:listfilesbat);
  psiRedirectStandardOutput = true;
  psiWindowStyle = SystemDiagnosticsProcessWindowStyleHidden;
  psiUseShellExecute = false;
  SystemDiagnosticsProcess listFiles;
  listFiles = SystemDiagnosticsProcessStart(psi);
  SystemIOStreamReader myOutput = listFilesStandardOutput;
  listFilesWaitForExit();
  
  if (listFilesHasExited) 
  { 
    string output = myOutputReadToEnd(); 
    thisprocessResultsText = output;
  }
}
使用默認的浏覽器打開URL
private void launchURL_Click(object sender SystemEventArgs e)
{
  string targetURL = @;
  SystemDiagnosticsProcessStart(targetURL);
}


From:http://tw.wingwit.com/Article/program/net/201311/13745.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.