Click here to Skip to main content
13,595,081 members
Rate this:
Please Sign up or sign in to vote.
See more: (untagged)
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 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 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 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
Please Sign up or sign in to vote.

Solution 2

Use the Timer class[^].

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180621.3 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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