开发者

Cross-thread Winforms control editing [duplicate]

开发者 https://www.devze.com 2022-12-25 03:54 出处:网络
This question already has answers here: Cross-thread operation not valid:开发者_开发问答 Control accessed from a thread other than the thread it was created on
This question already has answers here: Cross-thread operation not valid:开发者_开发问答 Control accessed from a thread other than the thread it was created on (22 answers) Closed 9 years ago.

how can I edit the text in a windows form element if the code that is editing the text 'belongs' to a seperate thread from the one that contains the windows form? I get the exception:

Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.

Thank you.


You will need to use Control.Invoke method like this:

textbox1.Invoke((MethodInvoker)(() =>
   {
     textbox1.Text="some text";
   }));

Check this article too: Threading in UIs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号