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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:12:13+00:00 2026-05-24T18:12:13+00:00

I have a Windows Form that runs a test, EngTest_F(), when you click a

  • 0

I have a Windows Form that runs a test, EngTest_F(), when you click a button on the form. This function is called from a native DLL. I’ve also created a backgroundworker in the managed form code that calls a function GetSicStatusMsg to update a textbox in the form.

In my native EngTest_F function, I have functions that push text updates onto a queue of strings. Then when GetSicStatusMsg is called, it checks the queue for strings and prints them out into the richTextBox in the windows form.

What I need to happen is for the backgroundworker to continuously run GetSicStatusMsg so I can get real-time progress on how the test is running. What’s actually happening is that EngTest_F runs, and then about a second after it finishes, all the status messages are printed out at once.

Is there a way to accomplish what I want to do? Or is there an easier approach? This is my first time using threads and the documentation is a bit lacking.

    private: void GetSicStatusMsg()
         {
             try
             {
                 while(GetNumStatusMsgs())
                 {
                     String^ Status = gcnew String(GetStatusMsg().c_str());
                     DisplayStatus(Status, DISPLAY_SIC);
                 }
             }
             catch(SIC_Error *Err)
             {
                 if(Err->ErrorCode != NO_CONTROLLER)
                 {
                     String^ Error = gcnew String(Err->ErrorMsg.c_str());
                     DisplayStatus(Error,DISPLAY_SIC);
                 }
             }
             catch(Exception ^Ex)
             {
                 DisplayStatus(Ex->Message,DISPLAY_SIC);
             }
         }

    private: System::Void button1_Click(System::Object^  /*sender*/, System::EventArgs^  /*e*/) 
         {      
             this->button1->Enabled = false;

             // Enable the Cancel button while 
             // the asynchronous operation runs.
             this->button4->Enabled = true;

             // Start the asynchronous operation. Needs to be running while EngTest_F is running
             backgroundWorker1->RunWorkerAsync();

             EngTest_F();
         }

    private: System::Void backgroundWorker1_ProgressChanged(System::Object^  sender, System::ComponentModel::ProgressChangedEventArgs^  e) 
         {
             GetSicStatusMsg();
         }

    private: void backgroundWorker1_RunWorkerCompleted( Object^ sender, RunWorkerCompletedEventArgs^ e )
         {
             // Enable the Start button.
             button1->Enabled = true;

             // Disable the Cancel button.
             button4->Enabled = false;
         }

    private: void backgroundWorker1_DoWork( Object^ sender, DoWorkEventArgs^ e )
         {
             // Get the BackgroundWorker that raised this event.
             BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);

             worker->ReportProgress(0);
         }
  • 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-24T18:12:15+00:00Added an answer on May 24, 2026 at 6:12 pm

    It seems like your code is backwards. The UI thread should update the UI, and the background thread should do the long-running task (I guess that’s EngTest_F()). One way to approach this is with a System.Windows.Forms.Timer component. Set up a timer with Interval=50 or so, which calls GetSicStatusMsg() to update the UI. Enable the timer when the task starts, and disable it when the task is complete.

    I’m not much of an expert in BackgroundWorker (I tend to use ordinary Thread objects myself), but I bet you need to call ReportProgress whenever the task progresses; your code only calls ReportProgress once. I recommend using a plain Thread + a Timer in your case, because it’s probably difficult for your unmanaged code to call BackgroundWorker.ReportProgress().

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

Sidebar

Related Questions

Does anyone know of a fast way in VB to go from a string
In my WiX installer I want to gracefully close the application that is about
I'd like some advice on building in known errors. Let's say I have a
I am struggling in seting up a the basic architecture for my ASP.NET MVC
In my application I am using a timer to check for updates in an
The process of compiling, creating exe and running it is very slow on my
How can I simulate an OnDestroy event for a TFrame in Delphi? I naively
A strange error begans to happen with my XNA project on a new pc.
I'm looking into figuring out how to add a deskband as a toolbar to
I wanted to be able to hide part of my application window to display

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.