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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:01:20+00:00 2026-05-20T11:01:20+00:00

I have a calculating thread function which invokes message function from other thread using

  • 0

I have a calculating thread function which invokes message function from other thread using Invoke and I want that calculating thread to get value(of valuetype, like integer) from that message function. How can I do this?

The problem is that I still get old value of x variable after Invoke(…) and I expect value of 15

delegate void mes_del(object param);

void MyThreadFunc()
{
...
int x = 5;
object [] parms = new object []{x};
Invoke(new mes_del(MessageFunc), (object)parms);
...
}

void MessageFunc(object result)
{
   int res = 15;
   (result as object[])[0] = res;
}

I tried some approaches like using object[], object as parameters with no success. I though boxing/unboxing operations should occur in such a case but they don’t.
Should I use auxiliary type like it is done in .NET event mode and create mediator object like
class holder
{
public int x;
}

  • 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-20T11:01:20+00:00Added an answer on May 20, 2026 at 11:01 am
    int x = 5;
    object [] parms = new object []{x};
    

    What the above code does is declare a local variable, assign it the value 5, then construct an object[] array containing one element which is a copy of that local variable.

    You then pass this array into your Invoke call.

    I think what you’ll find is that after Invoke is called, parms[0] is 15. But this does not affect x, which would actually have to be passed as a ref parameter for any method to be able to modify its local value.


    What I’ve seen done before is something like this:

    class Box<T>
    {
        public T Value { get; set; }
    }
    

    Then you could do:

    void MyThreadFunc()
    {
        var x = new Box<int> { Value = 5 };
    
        // By the way, there's really no reason to define your own
        // mes_del delegate type.
        Invoke(new Action<Box<int>>(MessageFunc), x);
    }
    
    void MessageFunc(Box<int> arg)
    {
        arg.Value = 15;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ class that I'm using from my Objective-C++ controller in my
I have a program that loads a file (anywhere from 10MB to 5GB) a
I have one main thread that does some rather CPU intensive operation. The thread
I have a GridControl which I populate using a BackgroundWorker . Then I'm using
I have a function which needs to be invoked with a different number of
I have a function which is passed two structures by reference. These structures are
I have this formula in a cell: =GetData(Channel_01,Chicago) Which executes this code: Public Function
So I have an application that needs to get a date focus so it
Hey there, I want to evaluate a mathematical function (user-defined) which returns several values
I have a function that accepts a large array of x,y pairs as an

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.