首页 | 麦客学吧 | 视频教程 | FLASH小游戏 | 素材下载 | 常用工具
您当前的位置:首页 > 程序开发 > C# > 正文

C# 中启动进程的三种方法

出处:麦客学吧 [2007-6-28 17:49:26] 作者:佚名 点击数:189

讨论交流:http://x8.maicoo.com/team/8763.html

1.启动子进程,不等待子进程结束
private void simpleRun_Click(object sender, System.EventArgs e)
{ System.Diagnostics.Process.Start(@"C:\listfiles.bat");
}
2.启动子进程,等待子进程结束,并获得输出
 1private void runSyncAndGetResults_Click(object sender, System.EventArgs e)
 2{
 3    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
 4    psi.RedirectStandardOutput = true;
 5    psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 6    psi.UseShellExecute = false;
 7    System.Diagnostics.Process listFiles;
 8    listFiles = System.Diagnostics.Process.Start(psi);
 9    System.IO.StreamReader myOutput = listFiles.StandardOutput;
10    listFiles.WaitForExit(2000);
11   
12    if (listFiles.HasExited) 
13    { 
14        string output = myOutput.ReadToEnd(); 
15        this.processResults.Text = output;
16    }
17}
183.使用默认的浏览器打开URL
1private void launchURL_Click(object sender, System.EventArgs e)
2{
3    string targetURL = @http://www.duncanmackenzie.net;
4    System.Diagnostics.Process.Start(targetURL);
5}
http://crush.cnblogs.com/archive/2006/06/09/421398.html

【责任编辑: lanier

素材中心
麦客酷站赏析频道

精彩图文推荐

关于本站 - 联系站长 - 广告服务 - 合作伙伴 - 网站地图 - 版权声明 - 报告错误 - 收藏本站 | Http://www.MaiCoo.com

Copyright © 2005 - 2008 MaiCoo.com All Rights Reserved

违法和不良信息举报中心 本站服务器空间和带宽由雷克斯网络提供赞助
浙ICP备06017818号