CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2014
    Location
    Las Vegas, NV
    Posts
    85

    [RESOLVED] MFC ProgressBar makes Application Slow

    Hello
    I have a problem with my progress bar:
    Code:
                            std::string line;
    			std::ifstream infile(ExtractFromFile, std::ios::binary);
    			while (std::getline(infile, line))
    			{
    				MainDialog->StockList.push_back(line.c_str());
    				TProgressBar.SetStep(1);
    				TProgressBar.StepIt();
    			}
    My list has about 5 MB. If i use TProgressBar stepit() then it takes about 20 seconds, without it it takes about 1 second. The difference is huge.
    Is there any way to make it faster ?
    Thank you!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC ProgressBar makes Application Slow

    Change the step size and only set the step on every 10 lines. There's no need to be that granular.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: MFC ProgressBar makes Application Slow

    Why are you setting the step size every time through the loop?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Sep 2014
    Location
    Las Vegas, NV
    Posts
    85

    Re: MFC ProgressBar makes Application Slow

    Code:
     
    		        int CountNr = 0;
                            std::string line;
    		        std::ifstream infile(ExtractFromFile, std::ios::binary);
    			while (std::getline(infile, line))
    			{
    		                CountNr++;
    				MainDialog->StockList.push_back(line.c_str());
    		                if (CountNr==10) {
    				TProgressBar.SetStep(10);
    				TProgressBar.StepIt(); }
    			}
    Now its 10 times faster.
    Thank you guys!

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: [RESOLVED] MFC ProgressBar makes Application Slow

    Why is SetStep() within the loop?

    When CountNr equals 10, shouldn't it be reset to 0?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: [RESOLVED] MFC ProgressBar makes Application Slow

    Code:
    		        int CountNr = 0;
    		        int step = 100;
    			TProgressBar.SetStep(step);
                            std::string line;
    		        std::ifstream infile(ExtractFromFile, std::ios::binary);
    			while (std::getline(infile, line))
    			{
    		                CountNr++;
    				MainDialog->StockList.push_back(line.c_str());
    		                if (0 == CountNr % step)
    					TProgressBar.StepIt();
    			}
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured