看板 C_Sharp 關於我們 聯絡資訊
我寫了一隻winForm程式,背後會呼叫另外一隻程式去執行一些東西, 一段code如下: Form1_Load { //do something //RunProcess(); } bool RunProcess() { myProcess = new Process(); //... myProcess.Start(); myProcess.EnableRaisingEvents = true; myProcess.Exited += new System.EventHandler(MyProcessExited); //.. return true; } void MyProcessExited(object sender, EventArgs e) { myProcess.Close() //...改變一些UI的值 MessageBox.Show("完成"); //結束 } 但是程式在背景程式結束後,跳出完成之後,UI的部份就會當掉。 請問有沒有人知道我的程式寫法錯在哪?或是犯了哪個設計上的問題? thanks -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.59.164.109
ST9619:改變UI的值時cross thread?? 03/23 04:13
ideaup:更改 myProcess.Close() 的執行時機,看看 03/23 08:31
TCBeliever:感謝樓上兩位,我去嘗試一下。 03/23 11:11