Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI
I want the progress bar to have certain values after specific time intervals. but the Sleep function Stops the ui from appearing.
 
My Code
 
private: System::Void ProgressBarSave_Load(System::Object^  sender, System::EventArgs^  e) 
	        {
		        for (int i = 0; i < 4; i++)
			{
				Thread::Sleep(3000);
				progressBar1 -> Value +=25;	//progress Bar Value
				if ( i == 3)
				{
		                    Close();			//Closes The Dialog
				}
			}
		}
Posted 13-Nov-12 22:35pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Um.
Where do I start?
If you want a progress bar to show progress, then sleeping the thread is always going to be a silly move. Firstly because it stops the UI thread from actually changing the display, and secondly, because it doesn't allow any program to actually be made unless you have that working on a different thread. And if you have it working on a different thread, then why are you reporting progress as if it wasn't?
 
There are a couple of possibilities: make the progress bar a Marquee in which case it will rotate itself without your intervention, or do the job properly with a BackgroundWorker and ReportProgress
  Permalink  
Comments
BladeFireX at 14-Nov-12 4:30am
   
isn't there a delay like function in cli? if not, then how can i use ReportProgress?
and i do not have my code working on a different thread, and i have the progress bar opened up in a different dialog.
OriginalGriff at 14-Nov-12 4:42am
   
Why not move your code into a background worker on the dialog containing the progress bar?
Any other way is multiplying interconnections, and making your life harder.
For example, if the progress dialog is modal, then the thread that displays it is frozen until it returns - so no work can continue on that thread anyway...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use the Timer class[^].
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 385
1 DamithSL 210
2 Kornfeld Eliyahu Peter 210
3 OriginalGriff 180
4 Peter Leow 95
0 OriginalGriff 7,215
1 DamithSL 5,199
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,757
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100