I don't know how to acces a label element (myLabel
) from a different class outside my Control Class while using background worker.
I really don't know the correct syntax.
Thanks a lot.
This is my code:
public partial class BasicControl : UserControl
{
// ...
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
this.Invoke(new MethodInvoker(delegate { myLabel.Text = "THIS WORKS!"; }));
var moc = new MyOtherClass();
string result = moc.myMethod();
}
}
internal class MyOtherClass
{
public void myMethod()
{
myLabel.Text = "THIS DOES NOT WORK!"; // NOT WORKING
}
}
CodePudding user response:
Toggling the checkbox starts and stops the worker after instantiating CustomDoWorkContext
.