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

  • Home
  • SEARCH
  • 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 7794637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:49:59+00:00 2026-06-01T22:49:59+00:00

I am trying to invoke Invoke on a Dispatcher using the following overload: public

  • 0

I am trying to invoke Invoke on a Dispatcher using the following overload:

public object Invoke(Delegate method, params object[] args);

I want to use named arguments, but I can’t seem to find the syntax for the argument with the params modifier. All of the following won’t compile:

dispatcher.Invoke(method: () => { }, args: {});
dispatcher.Invoke(method: () => { }, args: new object[0]);
dispatcher.Invoke(method: () => { }, args: null);
dispatcher.Invoke(method: () => { }, args: new object[] {});
object[] foo = {};
dispatcher.Invoke(method: () => { }, args: foo);
dispatcher.Invoke(method: () => { }, args: new[] {"Hello", "World!"});

I found these two questions to which there seems to be no definite answers:

Named parameters with params

How to set named argument for string.Format?

So my question is: can it be done or not? If yes, how?

UDPATE

Daniel Hilgarth’s shows that yes params can be used with named parameters. I integrated his answer using this pattern:

Action method = () => { };
if (_dispatcher != null)
    _dispatcher.Invoke(method: method, args: null);
else
    method();
  • 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-01T22:50:00+00:00Added an answer on June 1, 2026 at 10:50 pm

    The following code compiles without problems:

    void Main()
    {
        Invoke(method: () => {}, args: new object[] {});
    }
    
    public object Invoke(Action method, params object[] args)
    {
        return null;
    }
    

    I had to change the type of the first parameter from Delegate to Action to make it compile, because () => {} can’t be converted to Delegate.

    Alternatively, the following does also compile:

    void Main()
    {
        Action method = () => {};
        Invoke(method: method, args: new object[] {});
    }
    
    public object Invoke(Delegate method, params object[] args)
    {
        return null;
    }
    

    My assumption is that you never got a compile error about the args parameter but about the method parameter saying “Cannot convert from ‘lambda expression’ to ‘System.Delegate’“. This problem is solved by either casting the lambda to an Action (Invoke(method: (Action)(() => {}) ...) or by defining a variable of type Action that is passed as parameter to the method (see above), because Action can implicitly be converted to Delegate.

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

Sidebar

Related Questions

When trying to invoke a method on an external webservice (over the Internet) it
I'm trying to invoke a method that takes a super class as a parameter
I am trying to use Desktop .browse() to invoke a URL, this works fine
I'm trying to invoke a dialog on the UI dispatcher : class DialogService :
I am new to WPF and have a question regarding dispatcher and Delegate.Invoke .
I am trying to compile a COM object in Matlab 2011a using Matlab Builder
I am trying to translate the following C# snippet to VB: public bool ShowHandlerDialog(string
I was pulling out my hair trying to figure out why the normal Dispatcher.Invoke
So I am trying to invoke methods on a page and I know the
I am trying to invoke an ANT target from Windows (right-click) file context menu.

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.