Re: [問題] 請問如何自動更新Form

看板C_Sharp作者時間18年前 (2005/10/07 12:47), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串4/6 (看更多)
※ 引述《glenn7012 (垃圾桶)》之銘言: : ※ 引述《saker ()》之銘言: : 我的認知 簡單說 : Form本身是一個UI thread : 像迴圈或是IO等需要佔時間處理 不要寫在UI thread裡 : 而放到另一個background thread : 在background thread有需要變動UI時 再invoke訊息到UI thread : 程式修改如下 : private void button1_Click(object sender, System.EventArgs e) : { : System.Threading.Thread backgroundthread= : new System.Threading.Thread(new System.Threading.ThreadStart(process)); : backgroundthread.Start(); : } : delegate void delegate_updateUI(int x,int y); : private void updateUI(int x,int y) : { : //更改form上object的location : } : private void process() //background thread : { : for (XXXX) : { : int x,y; : // processing : // 送訊息到UI thread : this.Invoke(new delegate_updateUI(this.updateUI),new object[] {x,y}); : System.Threading.Thread.Sleep(100); : } : } : 以上分兩個thread後 for迴圈就不會影響UI運作了 : 尤其迴圈越久 UI運作相對越順暢 感謝  在.NET Framework可以動.. 不過我現在用的是 .NET Compact Framework 就不能動了 會掛在Thread.Sleep那... 可以幫忙解釋一下 再度非常感謝... -- 熊熊加油! ▄ █▄ █▌▄▄▄ ▄█ ▌▌ La New █████████▄▄▄ ▄███▄▄ ▄█ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.151.70

10/09 21:41, , 1F
我對dotnet CF不是很熟^^" 沒有這樣的經驗
10/09 21:41, 1F

10/09 21:59, , 2F
或許你可以多看multithread範例尤其是跟UI thread互動的
10/09 21:59, 2F

10/09 22:01, , 3F
或是doevent的做法也可以試試
10/09 22:01, 3F

10/09 22:17, , 4F
http://0rz.net/1c0Lc 這裡有兩種做法的範例
10/09 22:17, 4F
文章代碼(AID): #13HVtXlm (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #13HVtXlm (C_Sharp)