Post navigation

Updating GUI from Other Threads in C#

I’ve been meaning to write this down for a while. There is a really easy way of updating controls and generally updating the GUI of your main thread from another thread using BeginInvoke.

Create a global delegate for your Form class eg:

public delegate void InvokeDelegate(string input);

This means the delegate takes in a single argument (a string in this case). Next create a method to call to update the controls or do anything really. My method just appends text to a textbox:

public void UpdateLog(string input)
{
textboxLog.AppendText(input);
}

Now when you want to call this method from threads other than the main thread you create an object array, put in your input variables and use BeginInvoke to call your delegate which in turn calls your method:

6 thoughts on “Updating GUI from Other Threads in C#”

Thank you very mutch for your help, I have seeked so long about this problem and don’t found somethings helpfull, as over hier. I wish you and your families a Merry Christmas and the very best for next year, especially health, luck and good business!!!

Categories

About Me

A manager and developer for research and business groups, including large scale organisations in the fields of science, engineering and medical research. Technically proficient in a wide range of technologies and languages, including online application and database development, as well as an interface designer based on established design patterns.

Gained a PhD in Electronic, Electrical and Computer Engineering from the University of Birmingham on the subject of "Multimodal Intent Recognition for Natural Human-Robotic Interaction".

Currently working as a Java Developer in Shoreditch, London. Interests include the application of modern development techniques to patient record systems, collaborative research methods, distributed systems for healthcare support, web based patient record and decision support systems, data sharing and multi-platform interoperability.

Subscribe to my Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.