从线程更新Windows窗体控件 [英] Updating a windows forms control from a thread

查看:84
本文介绍了从线程更新Windows窗体控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在采访中已经多次提出这个问题而且我不知道他们正在寻找什么:


如何你在.NET中更新一个控件的属性,比如一个线程的textbox.text属性,

?在我看来,你只是正常更新它。

是面试官在这里寻找的?谢谢。


- W

I''ve gotten this question a couple of times in interviews and I don''t know
what they are looking for:

How do you update a control''s property, such as a textbox.text property,
from a thread, in .NET? It seems to me you just update it normally. What
are the interviewers looking for here? Thanks.

- W

推荐答案

" DW" <峰; dd ******** @ hotmail.com> schrieb:
"DW" <dd********@hotmail.com> schrieb:
我在采访中已经多次提出这个问题而且我不知道他们在寻找什么:

怎么做你在.NET中从一个线程更新一个控件的属性,如textbox.text属性,
?在我看来,你只是正常更新它。访问者在这里寻找什么?
I''ve gotten this question a couple of times in interviews and I don''t know
what they are looking for:

How do you update a control''s property, such as a textbox.text property,
from a thread, in .NET? It seems to me you just update it normally. What
are the interviewers looking for here?




始终在应用程序的主UI线程中创建表单。实例

Windows Forms表单和控件的成员对于多线程是不安全的,

因此直接访问它们会导致问题。除此之外,您的

表单需要一个消息泵,通常由应用程序的主UI提供

线程。


更多信息:


Windows窗体应用程序中的多线程

< URL:http://dotnet.mvps.org/dotnet/faqs/? id = multithreading& lang = en>


-

MS Herfried K. Wagner

MVP< URL:http: //dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>



Always create your forms in your application''s main UI thread. Instance
members of Windows Forms forms and controls are not safe for multithreading,
so accessing them directly can cause problems. In addition to that, your
forms need a message pump which is normally provided by the app''s main UI
thread.

More information:

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

从工作线程更新GUI是一个很大的禁忌......


(这就是我在这里引用某人)

Picho


" DW" <峰; dd ******** @ hotmail.com>在消息中写道

新闻:Bc ******************** @ rcn.net ...
Updating the GUI from a working thread is a big no-no...

(thats just me quoting someone here)
Picho

"DW" <dd********@hotmail.com> wrote in message
news:Bc********************@rcn.net...
我我在采访中已经多次提出这个问题而且我不知道他们在寻找什么:

如何更新控件的属性,例如.NET中的一个线程的textbox.text属性是什么?在我看来,你只是正常更新它。面试官在这里寻找什么?谢谢。

- W
I''ve gotten this question a couple of times in interviews and I don''t know
what they are looking for:

How do you update a control''s property, such as a textbox.text property,
from a thread, in .NET? It seems to me you just update it normally. What
are the interviewers looking for here? Thanks.

- W



谢谢Picho。那么具体来说,你会怎么做?你能提供一个小代码示例

吗?我一直在找一个不成功的。再次感谢




- DW

" Picho" < SP ******** @ telhai.ac.il>在消息中写道

news:%2 ****************** @ TK2MSFTNGP10.phx.gbl ...
Thanks Picho. Then specifically, how would you do that? Could you provide
a small code example. I''ve been looking for one unsuccessfully. Thanks
again.

- DW
"Picho" <SP********@telhai.ac.il> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
从工作线程更新GUI是一个很大的禁忌......

(那就是我在这里引用某人)

Picho

; DW" <峰; dd ******** @ hotmail.com>在消息中写道
新闻:Bc ******************** @ rcn.net ...
Updating the GUI from a working thread is a big no-no...

(thats just me quoting someone here)
Picho

"DW" <dd********@hotmail.com> wrote in message
news:Bc********************@rcn.net...
我已经得到了这个问题在采访中有几次,我不知道他们在寻找什么:

如何更新控件的属性,例如textbox.text属性,来自一个线程,在.NET?在我看来,你只是正常更新它。
在这里寻找的采访者是什么?谢谢。

- W
I''ve gotten this question a couple of times in interviews and I don''t
know what they are looking for:

How do you update a control''s property, such as a textbox.text property,
from a thread, in .NET? It seems to me you just update it normally.
What are the interviewers looking for here? Thanks.

- W




这篇关于从线程更新Windows窗体控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆