delegate parameters don't look right

Posted on 2011-10-13
Medium Priority
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

Accepted Solution

jagrut_patel earned 2000 total points
ID: 36966800
Instead of

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

try this

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

571 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