Home > Windows Forms > Cross-Threading Component Update

Cross-Threading Component Update

September 5th, 2009 admin Leave a comment Go to comments

public void TextComponentUpdate(String text, Object source)
{
 try
                    {
                //  Checks if the call for GUI update is from different thread
                        if (this.InvokeRequired)
                        {
CrossThreadingTextUpdate callback = new CrossThreadingTextUpdate(TextComponentUpdate);
                                    this.Invoke(callback, text, source);
                        }
                        else
                        {
                                    if (source.ToString().Equals("lbStatus"))
                                    {
                                                if (text.Equals("Clear"))
                                                    this.lbStatus.Items.Clear();
                                        }
else
                                {
                                            this.lbStatus.Items.Add(text);
                                }
                    }
                }
            }
            catch (Exception ex)
            {
                            TextComponentUpdate(ex.Message.ToString(), "lbStatus");
            }
        }

        delegate void CrossThreadingTextUpdate(String text, Object source);
Categories: Windows Forms Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.