Bee Eee Blog

Archive for January 3rd, 2008

Thread Safe calling to a form

by brian on Jan.03, 2008, under .NET, c#, c# coding GUI, coding

Here is an example of a thread-safe call into a form.

delegate void logCallback(string strLog);
private void log(string log)
{
  if (this.InvokeRequired)
  {
    logCallBack d = new logCallback(log);
    this.Invoke(d, log);
  }
  else
  {
     this.log( strLog );
  }
}

First we determine whether the overhead of an invoke can be dismissed. Then if we must invoke we first create an instance of the delegate. Then we call invoke. That’s it. Not too hard.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...