※ 引述《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
10/09 21:41, 1F
→
10/09 21:59, , 2F
10/09 21:59, 2F
→
10/09 22:01, , 3F
10/09 22:01, 3F
推
10/09 22:17, , 4F
10/09 22:17, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 6 篇):