C#啟動過程的幾種經常使用辦法。本站提示廣大學習愛好者:(C#啟動過程的幾種經常使用辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#啟動過程的幾種經常使用辦法正文
本文實例講述了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 = @http://www.jb51.net;
System.Diagnostics.Process.Start(targetURL);
}
願望本文所述對年夜家的C#法式設計有所贊助。