Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textbox text from background worker?

I've been trying to figure out how to get my textbox's text or other property from within a background worker. Does anybody know how to do this? I cannot pass it as a param because it needs to be real-time. Thanks for the help!

like image 991
user556396 Avatar asked Dec 16 '22 12:12

user556396


2 Answers

I think you need to just invoke the property (pseudo-code):

private void bgw1_DoWork(object sender, DoWorkEventArgs e)
{
  // looping through stuff
  {
    this.Invoke(new MethodInvoker(delegate { Text = textBox1.Text; }));
  }
}
like image 127
LarsTech Avatar answered Jan 01 '23 19:01

LarsTech


Use the ReportProgress method and event of the Background worker. That will switch to the correct thread for you.

like image 45
Emond Avatar answered Jan 01 '23 19:01

Emond