作者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
1F:→ glenn7012:我对dotnet CF不是很熟^^" 没有这样的经验 10/09 21:41
2F:→ glenn7012:或许你可以多看multithread范例尤其是跟UI thread互动的 10/09 21:59
3F:→ glenn7012:或是doevent的做法也可以试试 10/09 22:01