作者saker ()
看板C_Sharp
標題Re: [問題] 請問如何自動更新Form
時間Fri Oct 7 12:50:01 2005
※ 引述《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
→ glenn7012:我對dotnet CF不是很熟^^" 沒有這樣的經驗 10/09 21:41
→ glenn7012:或許你可以多看multithread範例尤其是跟UI thread互動的 10/09 21:59
→ glenn7012:或是doevent的做法也可以試試 10/09 22:01