Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-thread Winforms control editing [duplicate]

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.

like image 852
Xenoprimate Avatar asked Nov 27 '22 12:11

Xenoprimate


1 Answers

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

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

Check this article too: Threading in UIs

like image 86
Giorgi Avatar answered Dec 16 '22 02:12

Giorgi