• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

delegate parameters don't look right

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 });
  }
  else
  {
    // It's on the main UI thread, no need for Invoke
    try
    {
      textControl.Text = text;
    }
    catch (Exception e)
    {
      Log("SetTextControl: Exception updating text control: " + e.Message);
    }
  }
}

Open in new window

0
deleyd
Asked:
deleyd
1 Solution
 
jagrut_patelCommented:
Instead of

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

try this

this.BeginInvoke (d, new object[] { textControl, text });
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now