Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Status Strip Progress bar graphics not accurate???!!!

Status Strip Progress bar graphics not accurate???!!!

Scheduled Pinned Locked Moved C#
tutorialgraphicshelpquestion
7 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LongRange Shooter
    wrote on last edited by
    #1

    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.

    L D A T 4 Replies Last reply
    0
    • L LongRange Shooter

      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.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      LongRange.Shooter wrote:

      and sleep the thread for 1 second.

      Then what? What code executes after the sleep? You are sleeping the main or UI thread so no updating to the screen will occur.

      led mike

      1 Reply Last reply
      0
      • L LongRange Shooter

        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.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • L LongRange Shooter

          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.

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          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!]

          1 Reply Last reply
          0
          • L LongRange Shooter

            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.

            T Offline
            T Offline
            Tony Pottier
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              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

              L Offline
              L Offline
              LongRange Shooter
              wrote on last edited by
              #6

              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 );
              	}
              
              D 1 Reply Last reply
              0
              • L LongRange Shooter

                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 );
                	}
                
                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups