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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:10+00:00 2026-05-28T06:48:10+00:00

I use a thread to execute some process on a machine. Eventually, the progress

  • 0

I use a thread to execute some process on a machine. Eventually, the progress is reported back in an other thread. To update the GUI with the status of the process, I use a delegate like this:

public delegate void UpdateProgressDelegate(string description, int scriptnumber);
public void UpdateProgress(string description, int scriptnumber) {
    if (treeView.InvokeRequired) {
        treeView.Invoke(new UpdateProgressDelegate(UpdateProgress), description, scriptnumber);
        return;
    }
    // Update the treeview
}

And to call this delegate I use:

form.UpdateProgress("Ready", 3);

When the Invoke is called, I get a TargetParameterCountException: Parameter count mismatch.
I thought I could fix this by placing the string and int parameters in a single object like this:

public delegate void UpdateProgressDelegate(object[] updateinfo);
public void UpdateProgress(object[] updateinfo) {
    string description = (string) updateinfo[0];
    int scriptnumber = (int) updateinfo[1];
    if (treeView.InvokeRequired) {
        treeView.Invoke(new UpdateProgressDelegate(UpdateProgress), new object[] { description, scriptnumber });
        return;
    }       
    // Update the treeview
}

And to call it I use:

form.UpdateProgress(new object[] {"Ready", 3});

But this doesn’t work either. I keep getting the same TargetParameterCountException. Any ideas how I could fix this? Thanks in advance!

  • 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-28T06:48:11+00:00Added an answer on May 28, 2026 at 6:48 am

    I would say: do it the easy way:

    treeView.Invoke((MethodInvoker)delegate {
        UpdateProgress(description, scriptnumber);
    });
    

    or (equally):

    treeView.Invoke((MethodInvoker) () => UpdateProgress(description, scriptnumber));
    

    This gives you static-checking at the compiler, and IIRC MethodInvoker is checked explicitly, and called with Invoke() rather than DynamicInvoke(), making it faster too.


    Re why it doesn’t work; in your example with:

    public delegate void UpdateProgressDelegate(object[] updateinfo);
    

    you are actually passing two parameters; to disambiguate and pass a single array to a params here, you need to double-wrap it:

    treeView.Invoke(new UpdateProgressDelegate(UpdateProgress),
        new object[] { new object[] {description, scriptnumber }});
    

    Basically, the outer array is the “array of all the parameters”, which contains a single element, which is the array that we wan’t to pass as the first parameter (updateinfo).

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

Sidebar

Related Questions

How is it possible to get/use/return a thread from an execute queue ( =
I have some code where I use a thread static object in C#. [ThreadStatic]
I want to use Thread.VolatileWrite() (or an equivalent function) to change the value of
If we want to use thread specific data in a multithreaded application, how to
If i use thread like this: void foo() { new Thread().Start(); } since the
Executor seems like a clean abstraction. When would you want to use Thread directly
I wanted to use boost::thread in my program, but get the following compiler error
What is the use of Thread.BeginThreadAffinity() method in Thread class ? It will be
Is it possible to use BackGroundWorker thread in ASP.NET 2.0 for the following scenario,
I'm trying to use a Thread in a simple winform. I have a ListBox

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.