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