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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:40:46+00:00 2026-06-01T17:40:46+00:00

Background worker, passing variables are not working, in my example I explain everything, I

  • 0

Background worker, passing variables are not working, in my example I explain everything, I put only the functions that were important, I have the other functions from the BackgroundWorker.

int TheFunction(unordered_map<std::string,std::string> options, BackgroundWorker^ worker, DoWorkEventArgs ^ e){

    if(options["option1"].compare("options") == 0){
            //...
        }

        return 0;
}

    void backgroundWorker2_DoWork(Object^ sender, DoWorkEventArgs^ e ){
         BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);     
        //e->Result = TheFunction( safe_cast<Int32>(e->Argument), worker, e ); //That's how I do to send an integer value and works just fine, but I don't know how to send non-numeric values with safe_cast or something that works, in the function it looks like this: TheFunction(int index, ...) it works fine, I want to know with unordered_map or with strings also would work, I want more than one argument if you can do with std::string
          e->Result = TheFunction(safe_cast<unordered_map<std::string,std::string>>(e->Argument)); //I tried this, and it didn't work

    }


void CallBackgroundWorker(){
         this->backgroundWorker2 = gcnew System::ComponentModel::BackgroundWorker;
         this->backgroundWorker2->WorkerReportsProgress = true;
         this->backgroundWorker2->WorkerSupportsCancellation = true;
         this->backgroundWorker2->DoWork += gcnew DoWorkEventHandler( this, &GUISystem::backgroundWorker2_DoWork );
         this->backgroundWorker2->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler( this, &GUISystem::backgroundWorker2_RunWorkerCompleted );
         this->backgroundWorker2->ProgressChanged += gcnew ProgressChangedEventHandler( this, &GUISystem::backgroundWorker2_ProgressChanged );


         unordered_map<std::string,std::string>* options = unordered_map<std::string,std::string>();
         options["option1"] = "valor1";
         options["option2"] = "valor2";

         this->backgroundWorker2->RunWorkerAsync(options);
}

So how do I do to send the unordered_map or a std::string (more than 1 arguments) ?

thanks in advance. that would help a lot.

  • 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-01T17:40:47+00:00Added an answer on June 1, 2026 at 5:40 pm

    This line:

    unordered_map<std::string,std::string>* options = unordered_map<std::string,std::string>();
    

    isn’t legal even in standard C++. A pointer needs to store an address, not an object. So probably you meant to say new to use dynamic allocation (after all, the object needs to survive until the callback runs on the other thread).

    At that point, you can wrap the pointer inside System::IntPtr, and in the callback, cast the result of ToPointer().

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

Sidebar

Related Questions

I have a background worker that stops after 100 iterations. Like this: BackgroundWorker bgWorker
Scenario I have a background worker in my application that runs off and does
lets say i have a background worker in a class that perform db query
Background I have a Spring batch program that reads a file (example file I
I have some code that can spawn background worker threads from anywhere within it.
I have a WPF application with two background worker threads that operate while loading.
I have a background worker that is started on the main thread as shown
I have a background worker that does many GUI interactions, but my problem is
I have a background worker running a long database task. i want to show
I have a background worker which can be cancelled. The normal flows interrupt itself

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.