从线程更新GUI控件 [英] Updating GUI controls from threads
问题描述
我有一个线程正在运行,在这个线程的某一点上,我正在调用一个
方法来更新GUI控件。从网上我已经读过更新
来自工作线程的GUI控件是不好的做法。
线程myThread =新线程(新的ThreadStart(Worker)) ; ...
myThread.Start();
public void工人()
{
.. ..
updateGUI();
....
}
有人可以帮我解决。
在此先感谢
好奇写道:
我有一个线程正在运行,并且在这个线程的某个点上,我正在调用一个
方法来更新GUI控件。从网上我已经读过,从工作线程更新GUI控件是不好的做法。
这不仅是不好的做法,而是''甚至不允许使用.NET 2.请参阅Jon's
页面,了解您需要的所有信息:
http://www.yoda.arachsys.com/csharp/...winforms.shtml
Oliver Sturm
-
提供专家编程和咨询服务
参见 http://www.sturmnet.org (尝试/博客)
这里有一些关于这个主题的更好的文章:
http://msdn.microsoft.com/library/de...ms06112002.asp
http:// msdn。 microsoft.com/library/de...ms08162002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
>
-
HTH,
Kevin Spencer
Microsoft MVP
。 .Net开发商
歧义具有一定的品质。
" Oliver Sturm" <醇**** @ sturmnet.org>在消息中写道
news:xn **************** @ msnews.microsoft.com ...Curious写道:
我有一个线程正在运行,并且在这个线程的某一点上,我正在调用一个
方法来更新GUI控件。从网上我已经读到,从工作线程更新GUI控件是不好的做法。
这不仅是不好的做法,甚至不允许在.NET 2.请参阅Jon的
页面,了解您需要的所有信息:
http://www.yoda.arachsys.com/csharp/...winforms.shtml
Oliver Sturm
-
提供专家编程和咨询服务
请参阅 http ://www.sturmnet.org (尝试/博客)
谢谢,我自己犯了这个错误,在我看到这篇文章之前,我甚至都没有意识到这是一个
的错误。
我看过Jon的文章但我还有一个问题...
文章以从不调用任何m开头控件上的方法或属性
在另一个线程上创建。我明白为什么我们不应该试图改变
控制,但是我们能够从中读取吗?我们可以调用获取吗?属性?可以
我们调用一个不会改变控制的方法吗?
Javaman
" Oliver斯特姆"写道:
好奇写道:
我有一个线程正在运行,并且在这个帖子的某一点上我正在调用一个
更新GUI控件的方法。从网上我已经读到,从工作线程更新GUI控件是不好的做法。
这不仅是不好的做法,甚至不允许在.NET 2.请参阅Jon的
页面,了解您需要的所有信息:
http://www.yoda.arachsys.com/csharp/...winforms.shtml
Oliver Sturm
-
提供专家编程和咨询服务
请参阅 http ://www.sturmnet.org (尝试/博客)
Hi,
I have a thread running, and at a point in this thread I am calling a
method to update GUI controls. From the net I have read that updating
GUI controls from the worker thread is bad practice.
Thread myThread = new Thread(new ThreadStart(Worker));...
myThread.Start();
public void Worker()
{
....
updateGUI();
....
}
Can someone help me out.
Thanks in Advance
Curious wrote:
I have a thread running, and at a point in this thread I am calling a
method to update GUI controls. From the net I have read that updating
GUI controls from the worker thread is bad practice.
It''s not only bad practice, it''s not even allowed in .NET 2. See Jon''s
page for all the information you need about this:
http://www.yoda.arachsys.com/csharp/...winforms.shtml
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
Here are a couple more good articles on the topic:
http://msdn.microsoft.com/library/de...ms06112002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:xn****************@msnews.microsoft.com...Curious wrote:I have a thread running, and at a point in this thread I am calling a
method to update GUI controls. From the net I have read that updating
GUI controls from the worker thread is bad practice.
It''s not only bad practice, it''s not even allowed in .NET 2. See Jon''s
page for all the information you need about this:
http://www.yoda.arachsys.com/csharp/...winforms.shtml
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
Thanks, I''ve made this mistake myelf, and wasn''t even aware that it was a
mistake until I saw this post.
I''ve had a look at Jon''s article but I still have one question...
The article begins with "Never invoke any method or property on a control
created on another thread". I can see why we shouldn''t attempt to change the
control, but are we able to read from it? Can we invoke a "get" property? Can
we invoke a method which doesn''t change the control?
Javaman
"Oliver Sturm" wrote:
Curious wrote:I have a thread running, and at a point in this thread I am calling a
method to update GUI controls. From the net I have read that updating
GUI controls from the worker thread is bad practice.
It''s not only bad practice, it''s not even allowed in .NET 2. See Jon''s
page for all the information you need about this:
http://www.yoda.arachsys.com/csharp/...winforms.shtml
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
这篇关于从线程更新GUI控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!