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 213417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:16:35+00:00 2026-05-11T18:16:35+00:00

From what I’ve found in C#, the Control.Invoke method requires that you use a

  • 0

From what I’ve found in C#, the Control.Invoke method requires that you use a delegate with no input parameters. Is there any way around this? I would like to invoke a method to update the UI from another thread and pass to string parameters to it.

  • 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-05-11T18:16:35+00:00Added an answer on May 11, 2026 at 6:16 pm

    Which version of C# are you using? If you are using C#3.5 you can use closures to avoid passing in parameters.

    With C#3.5

    public static class ControlExtensions
    {
      public static TResult InvokeEx<TControl, TResult>(this TControl control,
                                                 Func<TControl, TResult> func)
        where TControl : Control
      {
        return control.InvokeRequired
                ? (TResult)control.Invoke(func, control)
                : func(control);
      }
    
      public static void InvokeEx<TControl>(this TControl control,
                                            Action<TControl> func)
        where TControl : Control
      {
        control.InvokeEx(c => { func(c); return c; });
      }
    
      public static void InvokeEx<TControl>(this TControl control, Action action)
        where TControl : Control
      {
        control.InvokeEx(c => action());
      }
    }
    

    Safely invoking code now becomes trivial.

    this.InvokeEx(f => f.label1.Text = "Hello World");
    this.InvokeEx(f => this.label1.Text = GetLabelText("HELLO_WORLD", var1));
    this.InvokeEx(() => this.label1.Text = DateTime.Now.ToString());
    

    With C#2.0 it becomes less trivial

    public class MyForm : Form
    {
      private delegate void UpdateControlTextCallback(Control control, string text);
      public void UpdateControlText(Control control, string text)
      {
        if (control.InvokeRequired)
        {
          control.Invoke(new UpdateControlTextCallback(UpdateControlText), control, text);
        }
        else
        {
          control.Text = text;
        }
      }
    }
    

    Using it simple, but you have to define more callbacks for more parameters.

    this.UpdateControlText(label1, "Hello world");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From your experience, are there any security measures that one should undertake on a
From a desktop application developer point of view, is there any difference between developing
From what I can gather, there are three categories: Never use GET and use
From the question here , There are two external libraries to use for http
From MSDN If there are no waiting threads, the wait handle remains signaled until
From here: http://www.codingwithoutcomments.com/ If you do use Singletons, try to use dependency injection instead
From epoll's man page: epoll is a variant of poll(2) that can be used
From reading a few questions and answers here, it seems that a telnet stream
From what I understand of ActionScript, there are two kinds of casts: var bar0:Bar
From viewing the source code that this code makes it looks like itemValue generate

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.