c# 调用外部程序
//本來看似非常簡單的。。程序是一個界面。左邊一個提示有個 checkbox 提示用戶"我知道了,請不要再顯示",右邊是運行QQ的一個按鈕。但是弄的時候弄了四個小時左右。經常是調試的時候是對的,但是有的時候點了按鈕過后沒有反映,
//不能夠運行外部程,//Events() 方法過后好些,但是偶爾還是會出現這情況,最后再加上。?System.Threading.Thread.Sleep(2000); 得到解決。。目前還沒有扯拐。
public static void RunQQ()
??????? {
??????????? //實例一個Process類,啟動一個獨立進程
????????????? Process p = new Process();
????????????? string command = @"d:\sysset\menu\runqq\runqq.bat";
??????????? //Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:
????????????? p.StartInfo.FileName = command;?????????? //設定程序名
????????????? p.StartInfo.Arguments = "/c " + string.Empty;??? //設定程式執行參數
????????????? p.StartInfo.UseShellExecute = false;??????? //關閉Shell的使用
????????????? p.StartInfo.RedirectStandardInput = true;?? //重定向標準輸入
????????????? p.StartInfo.RedirectStandardOutput = true;? //重定向標準輸出
????????????? p.StartInfo.RedirectStandardError = true;?? //重定向錯誤輸出
????????????? p.StartInfo.CreateNoWindow = true;????????? //設置不顯示窗口
????????????? p.Start();?? //啟動
???????????
????????????? //p.StandardInput.WriteLine(command);?????? //也可以用這種方式輸入要執行的命令
????????????? //p.StandardInput.WriteLine("exit");??????? //不過要記得加上Exit要不然下一行程式執行的時候會當機
???????????
??????? }
//里面有個非常關鍵。。就是要用到
Application.DoEvents();?? System.Threading.Thread.Sleep(2000);???Directory.CreateDirectory(@"e:\ok"); //新建文件夾?
?? if (!Directory.Exists(@"e:\ok"))//若文件夾不存在則新建文件夾??
??????????? {
??????????????? //顯示窗體.
??????????????? Application.Run(new Form1());
??????????? }
?
?
?
?
?
轉載于:https://www.cnblogs.com/fat_li/archive/2010/11/11/1874774.html
總結
- 上一篇: jquery vilidate 使用小
- 下一篇: C#多线程使用进度条