Which is the simplest way to update a Label
from another Thread
?
-
I have a
Form
running onthread1
, and from that I'm starting another thread (thread2
). -
While
thread2
is processing some files I would like to update aLabel
on theForm
with the current status ofthread2
's work.
How could I do that?
Best Answer
The simplest way is an anonymous method passed into
Label.Invoke
:Notice that
Invoke
blocks execution until it completes--this is synchronous code. The question doesn't ask about asynchronous code, but there is lots of content on Stack Overflow about writing asynchronous code when you want to learn about it.