C#: Update UI Component with Threadsafe Operation

Datetime:2016-08-22 22:13:54         Topic: C#          Share        Original >>
Here to See The Original Article!!!

Sometimes when you try to access UI component from a different thread, you’ll run into exception on you can’t access UI component from a different Thread than the original UI thread that creates the component.

For example, I have a Label, I would like to set the Label1.txt to some text from inside of a backgroundWorker.

They come up with a very simple way of update any UI component from a different thread.

How to use:

1. Download the following code and place it inside your own project.


2. In the function where you want to update the UI component, invoke this class.

For example:

this.InvokeEx(f => f.label1.Text = "updating label ...");


Put your ads here, just $200 per month.