Status Strip Progress bar graphics not accurate???!!!
-
I have a status strip which displays a progress bar during initialization and execution phases of my application. In the designer I set Max=100 Min=0 Step=10 The bar progresses as expected, but when I reach completion I set the bar value to 100, put out my complete message, and sleep the thread for 1 second. The Progress bar is always showing only about 80% of the progress bar painted. I've experimented by taking the value to 101 (for example) and it doesn't like that. I've also paused the code and validated that the value is indeed set to 100. Has anyone experienced this or (better yet) figured out how to fix this? Thanks in advance.
-
I have a status strip which displays a progress bar during initialization and execution phases of my application. In the designer I set Max=100 Min=0 Step=10 The bar progresses as expected, but when I reach completion I set the bar value to 100, put out my complete message, and sleep the thread for 1 second. The Progress bar is always showing only about 80% of the progress bar painted. I've experimented by taking the value to 101 (for example) and it doesn't like that. I've also paused the code and validated that the value is indeed set to 100. Has anyone experienced this or (better yet) figured out how to fix this? Thanks in advance.
-
I have a status strip which displays a progress bar during initialization and execution phases of my application. In the designer I set Max=100 Min=0 Step=10 The bar progresses as expected, but when I reach completion I set the bar value to 100, put out my complete message, and sleep the thread for 1 second. The Progress bar is always showing only about 80% of the progress bar painted. I've experimented by taking the value to 101 (for example) and it doesn't like that. I've also paused the code and validated that the value is indeed set to 100. Has anyone experienced this or (better yet) figured out how to fix this? Thanks in advance.
If you call Thread.Sleep after setting the Value of ProgressBar, the bar will not get painted, so you'll see this result. Putting the UI thread to sleep or tying it up doings other things prevents any painting of the form or its controls.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
I have a status strip which displays a progress bar during initialization and execution phases of my application. In the designer I set Max=100 Min=0 Step=10 The bar progresses as expected, but when I reach completion I set the bar value to 100, put out my complete message, and sleep the thread for 1 second. The Progress bar is always showing only about 80% of the progress bar painted. I've experimented by taking the value to 101 (for example) and it doesn't like that. I've also paused the code and validated that the value is indeed set to 100. Has anyone experienced this or (better yet) figured out how to fix this? Thanks in advance.
Hi, Controls are not updated at the instant that the new value is set and may never get updated if the UI thread is busy. To see if this is the problem you could insert a call to Application.DoEvents() immediately after setting the progress bar value to 100. Longer term you may need to separate your application processing into a separate thread so that the UI is free to update when you want it to. Alan. [EDIT: and like the others said, don't go to sleep!]
-
I have a status strip which displays a progress bar during initialization and execution phases of my application. In the designer I set Max=100 Min=0 Step=10 The bar progresses as expected, but when I reach completion I set the bar value to 100, put out my complete message, and sleep the thread for 1 second. The Progress bar is always showing only about 80% of the progress bar painted. I've experimented by taking the value to 101 (for example) and it doesn't like that. I've also paused the code and validated that the value is indeed set to 100. Has anyone experienced this or (better yet) figured out how to fix this? Thanks in advance.
As people have already pointed out, if you sleep the thread your UI will never have the change to get updated. Try to do this.Invalidate() before sleeping your thread. Application.DoEvents() is another workaround for this.
-
If you call Thread.Sleep after setting the Value of ProgressBar, the bar will not get painted, so you'll see this result. Putting the UI thread to sleep or tying it up doings other things prevents any painting of the form or its controls.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Okay...cut short my entire process. Here it is:
private void SetProgress( int progressValue, string message ) { this.loadProgress.Step = progressValue; this.loadProgress.PerformStep( ); this.loadStatus.Text = message; this.Refresh( ); Application.DoEvents( ); Thread.Sleep( 1000 ); }
-
Okay...cut short my entire process. Here it is:
private void SetProgress( int progressValue, string message ) { this.loadProgress.Step = progressValue; this.loadProgress.PerformStep( ); this.loadStatus.Text = message; this.Refresh( ); Application.DoEvents( ); Thread.Sleep( 1000 ); }
The Thread.Sleep is not required and is actually hindering the process by not allowing any code to execute on the thread you called Sleep on. DoEvents will yield the thread to processing the message loop (including painting) but you have to be VERY careful in using it. Since button presses and other UI controls will still work, you could end up with a user clicking twice on the same button because DoEvents allows both clicks to be processed.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008