Re: [問題] C#使用批次檔的問題

看板C_Sharp作者 (toyangel)時間12年前 (2011/12/06 02:48), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
可以試試把批次檔的值讀回來做判斷 例如 Process p = new Process(); p.StartInfo.FileName = "xxx.bat"; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.Start(); string str = ""; while(str != null) { str = p.StandardOutput.ReadLine(); ... ... } ※ 引述《markzog21 (殘羽星辰)》之銘言: : 小弟最近寫了一個程式 : 有使用到Process : oThreadA = new Thread(new ThreadStart(A)); : oThreadA.Start(); : oThreadB = new Thread(new ThreadStart(B)); : oThreadB.Start(); : 問題在A的執行緒裡面有使用到批次檔處理 : 而B執行緒希望等A執行完以後再執行 : 但我不知道C#要怎麼樣檢查批次檔執行的進度 : 我目前的寫法是下面 : --------- : A : { : for(int i = 0 ; i < 10000 ;i++) : { : using (StreamWriter sw = new StreamWriter(i + ".bat")) : { xxxxxxxxxxx : } : Process.Start(i + ".bat"); : } : } : B : { : oThreadA.Join(); : xxxxx : } : -------------- : 但還是沒有辦法在所有的批次檔跑完後再執行B : 請問版上 是否可指導迷津一下 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.192.44.213 ※ 編輯: toyangel 來自: 123.192.44.213 (12/06 02:49)

12/14 20:56, , 1F
process.waitforexit()
12/14 20:56, 1F
文章代碼(AID): #1EtH8QYc (C_Sharp)
文章代碼(AID): #1EtH8QYc (C_Sharp)