2

In C#: How do I access GUI-Elements, like buttons or labels in another thread?

Luke
  • 5,771
  • 12
  • 55
  • 77

2 Answers2

5

Use Invoke, like this:

Invoke((MethodInvoker)(()=>lblName.Text="Meep"));
Blindy
  • 65,249
  • 10
  • 91
  • 131
4

You can't.

Instead, you need to call Invoke or BeginInvoke to execute code on the UI thread.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964