delegate parameters don't look right

Posted on 2011-10-13
Last Modified: 2012-06-27
Something doesn't look right with this delegate. I changed it to pass the control as a parameter, instead of having a separate method for each control. But line 12 doesn't look right. I don't see how the control gets passed to the delegate.
delegate void SetTextControlDelegate(Control control, string text);

/* Call this method to change text on a form control (TextBox or Label) */
private void SetTextControl(Control textControl, string text)
  // Check if this method is running on a different thread
  // than the thread that created the control.
  if (textControl.InvokeRequired)
    // It's on a different thread, so use Invoke. (We call ourself through a delegate.)
    SetTextControlDelegate d = new SetTextControlDelegate(SetTextControl);
    textControl.BeginInvoke (d, new object[] { text });
    // It's on the main UI thread, no need for Invoke
      textControl.Text = text;
    catch (Exception e)
      Log("SetTextControl: Exception updating text control: " + e.Message);

Open in new window

Question by:deleyd
    1 Comment
    LVL 8

    Accepted Solution

    Instead of

    textControl.BeginInvoke (d, new object[] { text });

    try this

    this.BeginInvoke (d, new object[] { textControl, text });

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now