The question makes no sense just because you cannot change the label text from any thread except the UI thread. What is the UI thread? It relation to your label object, this is the thread which called
Application.Run
with the form which created all the controls owning your label. You can modify the label text (or anything at all) only in the same very thread. To trigger such change in any other thread, you can use the mechanism of
invocation which is implemented for UI thread for both WPF and
System.Windows.Forms
.
Instead of trying to modify any UI properties directly, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
If you want to delegate some actions to some thread which is not a UI thread, you will have to implement a similar synchronization and data passing mechanism by yourself. Please see my article where it is explained in detail:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^].
—SA