Click here to Skip to main content
11,641,971 members (58,417 online)
Rate this: bad
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++)
				progressBar1 -> Value +=25;	//progress Bar Value
				if ( i == 3)
		                    Close();			//Closes The Dialog
Posted 13-Nov-12 21:35pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Use the Timer class[^].
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
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...

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

  Print Answers RSS
0 DamithSL 245
1 Afzaal Ahmad Zeeshan 170
2 Sergey Alexandrovich Kryukov 159
3 OriginalGriff 110
4 Mika Wendelius 90
0 Mika Wendelius 460
1 DamithSL 353
2 OriginalGriff 315
3 Sergey Alexandrovich Kryukov 179
4 Afzaal Ahmad Zeeshan 169

Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2015
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