You are not Logged in
Would you like to Login or Register

Today is: 05 February 2012
Check this months hot topics

Updating form controls from another thread.

Form controls, by default, can only be updated by the forms thread. Otherwise an invoke must be used.

The example below shows a simple logging function that can be called by threads other than the forms.

delegate void LogSafeCall(string s);
        private void Log(string s)
        {
            if (EventsListBox.InvokeRequired)
            {
                LogSafeCall d = new LogSafeCall(Log);
                EventsListBox.Invoke(d, new object[] { s });
            }
            else
            {
                EventsListBox.Items.Add(s);
                EventsListBox.SelectedIndex = EventsListBox.Items.Count - 1;
            }
        }
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Dave Howard Skype
Author : Dave Howard
Published : 14 June 2006

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views

More Publications

System tray and balloon tips
Dave Howard - 14/06/2006
TraceListener creates huge log files
Lee Keable - 26/07/2006
Updating controls from another thread
Dave Howard - 14/06/2006
Missing App.Path
Lee Keable - 26/07/2006