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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:27:50+00:00 2026-06-10T05:27:50+00:00

I’m writing an application that communicates with some hardware using the MODBUS protocol. I’m

  • 0

I’m writing an application that communicates with some hardware using the MODBUS protocol.
I’m using this sample from Code Project.

While trying to optimize the code (mainly the PollFunction function), I’ve encountered with a very strange threads lock.

Instead of sending each line of string to the DoGUIUpdate delagate, I’m constructing a string array and sending it as a whole.

Doing so causes the application to crush with a System.Reflection.targetParametercountException: Parameter count mismatch error.

The original code:

public delegate void GUIUpdate(string paramString);
public void DoGUIUpdate(string paramString)
{
    if (InvokeRequired)
        BeginInvoke(new GUIUpdate(DoGUIUpdate), paramString);
    else
        lstRegisterValues.Items.Add(paramString);
}

private void PollFunction()
{
    ...
    string itemString;
    for (int i = 0; i < pollLength; i++)
    {
        itemString = "[" + Convert.ToString(pollStart + i + 40001) + "] , MB[" + Convert.ToString(pollStart + i) + "] = " + values[i];
        DoGUIUpdate(itemString);
    }
}

My code:

public delegate void GUIUpdate2(string[] paramString);
public void DoGUIUpdate2(string[] paramString)
{
    if (InvokeRequired)
        BeginInvoke(new GUIUpdate2(DoGUIUpdate2), paramString);
    else
    {
        lstRegisterValues.Items.Clear();
        lstRegisterValues.Items.AddRange(paramString);
    }
}

string[] valuesStrings;
private void PollFunction()
{
    ...
    valuesStrings = new string[pollLength];
    for (int i = 0; i < pollLength; i++)
    {
        valuesStrings[i] = "[" + Convert.ToString(pollStart + i + 40001) + "] , MB[" + Convert.ToString(pollStart + i) + "] = " + values[i];
    }
    DoGUIUpdate2(valuesStrings);
}

Any advice will be welcome.

  • 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-10T05:27:52+00:00Added an answer on June 10, 2026 at 5:27 am

    i think BeginInvoke(new GUIUpdate2(DoGUIUpdate2), paramString); is the problem…

    the second parameter of “begininvoke” accepts a param object[] params which will result in the call DoGuiUpdate(string1,string2,string3) which is not what you want…

    try encapsulate in the following way:

    BeginInvoke(new GUIUpdate2(DoGUIUpdate2), new[]{ paramString });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application that communicates using sockets. I have a server running
I am in the process of writing an application that communicates with several devices
I'm writing an application for the iPhone that communicates with a SQLite database but
I am writing an application using Sencha Touch that will require a login to
I'm doing a project over the summer that involves entirely re-writing a large application
I am writing an application that communicates with Active Directory and I need to
I am writing an application that uses OpenNETCF.IO.Serial (open source, see serial code here
I'm writing an application that communicates by sending bytes to the USB port. I'd
I am writing an application that communicates with other devices through SMSs. I was
I am writing a C# application that communicates with an old C DLL. I

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.