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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:31:02+00:00 2026-05-13T21:31:02+00:00

I am working on threading in MFC..I am not sure how to use threading..

  • 0

I am working on threading in MFC..I am not sure how to use threading.. I cant attain what i excepted!What I actually tried, is to read the directory and display the file names and at the same time,the progress control should show the progress..I created a dynamic static to display the file names and progress bar control to show the progress…What happens here is,its first displaying all the file names one by one and then after that its showing the progress…so,am bit confused..can anybody explain me how to do that or refer me some articles…if u want i can post the code

  • 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-13T21:31:03+00:00Added an answer on May 13, 2026 at 9:31 pm

    This appears to be creating 10 threads for each file

            for(int i =0;i<10;i++)
            {
                THREADINFOSTRUCT *_param = new THREADINFOSTRUCT;
               _param->_this = this;
                AfxBeginThread(MyThread,_param,THREAD_PRIORITY_ABOVE_NORMAL);
                ....
            }
    

    All 10 threads are simultaneously trying to set a single progress bar. (that’s bad)

    ts->_this->m_ProgressCtrl.SetRange (0, 500);
    while (ts->_this->m_ProgressCtrl.GetPos () < 500)
    {
        Sleep(250);
        ts->_this->m_ProgressCtrl.StepIt ();
    }
    

    We don’t see the code for creation of the progress bar. But it presumably belongs the the main thread. So when these 10 threads try and SetRange or GetPos or StepIt, they are actually sending messages to the main thread to tell it to do those things.

    Meanwhile the main thread is in the do {} }while(FindNextFileW(handle,&findData)); loop, and isn’t pumping messages. So those threads all wait until the loop is finished and the main thread goes back to its message pump.

    Then each of your threads wakes up and returns from calling SetRange, etc. But one at a time, since only message at a time can be processed by the main thread.

    For this to work, you need to move the FindNextFile loop into a thread, and you need to let the main thread go back to the pump so that the UI can be updated while things progress.

    You also need to stop trying to set the progress bar directly from any of your non-main threads. Instead use PostMessage to post messages back to the main thread and let it set the progress bar. That way your threads don’t end up blocking and waiting for the main thread to talk to the progress bar on their behalf.

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

Sidebar

Related Questions

I am currently working under the assumption that -performSelector:withObject:afterDelay: does not utilize threading, but
after reading a few articles, I am still not sure I understand Multi-threading to
Working with python interactively, it's sometimes necessary to display a result which is some
I working on project and have problem with threading and update of UI. I
I'm working on a simple job threading framework which is very similar to the
I'm working on a subclass of threading.Thread which allows its methods to be called
I am having some threading issues with a large app I am working on
Could someone explain to me the working and differences of above operations in multi-threading?
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with a SqlCommand in C# I've created a query that contains a IN

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.