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;
}
}