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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:38:31+00:00 2026-06-08T13:38:31+00:00

How can you delegate a function with parameters to an other thread in C#?

  • 0

How can you delegate a function with parameters to an other thread in C#?

If I try it on my own I get this error:

error CS0149: Method name expected

This is what I have now:

delegate void BarUpdateDelegate();
    private void UpdateBar(int Value,int Maximum,ProgressBar Bar)
    {
        if (Bar.InvokeRequired)
        {
            BarUpdateDelegate Delegation = new BarUpdateDelegate(Value, Maximum, Bar); //error CS0149: Method name expected
            Bar.Invoke(Delegation);
            return;
        }
        else
        {
            Bar.Maximum = Maximum;
            Bar.Value = Value;

            //Insert the percentage
            int Percent = (int)(((double)Value / (double)Bar.Maximum) * 100);
            Bar.CreateGraphics().DrawString(Percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(Bar.Width / 2 - 10, Bar.Height / 2 - 7));

            return;
        }
    }

I want to update from an other thread the progress bar in the main thread.

  • 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-08T13:38:34+00:00Added an answer on June 8, 2026 at 1:38 pm

    You don’t initialize a delegate with arguments:

    BarUpdateDelegate Delegation = new BarUpdateDelegate(Value, Maximum, Bar); //error CS0149: Method name expected
    Bar.Invoke(Delegation);
    

    Instead, pass those arguments to Invoke.

    BarUpdateDelegate delegation = new BarUpdateDelegate(UpdateBar);
    Bar.Invoke(delegation, Value, Maximum, Bar);
    

    You’ll also need to specify those arguments in your delegate definition. However, there is an easier way, using the built-in Action<...> delegates. I also made a couple other code improvements.

    private void UpdateBar(int value, int maximum, ProgressBar bar)
    {
        if (bar.InvokeRequired)
        {
            bar.Invoke(new Action<int, int, ProgressBar>(UpdateBar),
                       value, maximum, bar);
        }
        else
        {
            bar.Maximum = maximum;
            bar.Value = value;
    
            // Insert the percentage
            int percent = value * 100 / maximum;
            bar.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", 8.25f, FontStyle.Regular), Brushes.Black, bar.Width / 2 - 10, bar.Height / 2 - 7);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a delegate function that can 'wrap' some while/try/catch code around
Using a delegate I can call any function asynchronously. From the documentation I understand
I read that the new delegate method can attach more than one event to
To create a delegate from a method you can use the compile type-safe syntax:
I have a calculating thread function which invokes message function from other thread using
I want to create a function that recieve one parameter: 1. delegate that get
public delegate bool FunctieCompara(int a, int b); this is the delegate Simple function calls:
In Delphi we can delegate the implementation of an interface to another class, I'm
I believe that UIView objects can delegate control to views in iOS programming. However,
Can we have same delegate for two events ? which have same number of

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.