Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:18:40+00:00 2026-06-02T04:18:40+00:00

In the code from this link: http://c-sharp-programming.blogspot.com/2008/07/cross-thread-operation-not-valid.html , a delegate is used to update

  • 0

In the code from this link: http://c-sharp-programming.blogspot.com/2008/07/cross-thread-operation-not-valid.html, a delegate is used to update a text box’s value from a worker thread.

I can basically see what’s happening, but the syntax of this line specifically:

label1.Invoke(del, new object[] { newText });

is confusing to me. Can someone explain it please? Why do we use a new object array syntax for the delegate when there’s only one parameter?

Full code:

delegate void updateLabelTextDelegate(string newText);
private void updateLabelText(string newText)
{
 if (label1.InvokeRequired)
 {
     // this is worker thread
     updateLabelTextDelegate del = new updateLabelTextDelegate(updateLabelText);
     label1.Invoke(del, new object[] { newText });
 }
 else
 {
     // this is UI thread
     label1.Text = newText;
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:18:41+00:00Added an answer on June 2, 2026 at 4:18 am

    TL;DR:

    Control.Invoke is calling DynamicInvoke on your delegate which takes an object array of parameters to work with any delegate type.

    //

    The keyword delegate in C# in analagous to specifying a type of function pointer. You can use that type to pass methods of a specific signature. In your example, the signature is for a method that takes 1 arg (a string) and returns nothing (void). The method updateLabelText matches that sig. The line:

    updateLabelTextDelegate del = new updateLabelTextDelegate(updateLabelText);
    

    Is just a full-text way of saying:

    updateLabelTextDelegate del = updateLabelText;
    

    Then, you can pass your variable del, which is now a pointer to the method updateLabelText to the Control.Invoke method.

    label1.Invoke(del, new object[] { newText });
    

    Which thanks to params being using in the Control.Invoke signature, you don’t even have to explicitly say it’s an object[]

    label1.Invoke(del, newText);
    

    The Invoke takes an array of objects, which it’ll use as the args to the delegate given. (Yes your update method takes one string arg, keep reading) With your variable del, you could call updateLabelText yourself:

    del(newText);
    

    Which would essentially be the same as:

    updateLabelText(newText);
    

    Inside Control.Invoke, they are calling your del method, but it doesn’t have to know how many args it takes thanks to some helper methods on delegates. You would find something like this:

    EDIT I did some deep digging for science, the invocation internally is more like:

    del.DynamicInvoke(args);
    

    Where args is an object[]. For more info on things you can do with your delegate variable (which is of type Delegate), read more here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know why the same code from this page http://emacsformacosx.com/ would not render
I try to access information from Twitter and I followed this link: http://code.google.com/p/sociallib/wiki/SocialLibGuide I
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
This is the output to my program from this link (http://www.rottentomatoes.com/movie/box_office.php). As you can
I followed Google's Map View tutorial from this link http://developer.android.com/resources/tutorials/views/hello-mapview.html I've done the first
I have a code download image from link http://www.bitrepository.com/download-image.html When start is link format:
i have this code: <html xmlns:fb=https://www.facebook.com/2008/fbml> <body> <script src=http://connect.facebook.net/en_US/all.js></script> <div id=fb-root></div> <script> // assume
I am trying the RSS Feed code from this website (http://javamix.wordpress.com/category/programs/rss-feed/) It worked fine.
I have borrowed code from this link PHP regex templating - find all occurrences
When I have download sample code from this link and than try to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.