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. Progress bar problem

Progress bar problem

Scheduled Pinned Locked Moved C#
htmlhelp
7 Posts 2 Posters 0 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.
  • M Offline
    M Offline
    Martin23
    wrote on last edited by
    #1

    Hi, I am making an application that simply gets all the html from a webpage and filters out the data I want. The problem is that I want a progressbar to indicate it is working (using the "marquee" style). My code looks like this; Private void getWebData() { progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Value = 100; //simple code to get wepage... //simple code to filter out data I want... //put data into listbox progressBar1.Value = 0; progressBar1.Style = ProgressBarStyle.Continuous; } I thought that this would set the progressbar going, then do the work, then stop the progress bar, but instead the progress bar just doesnt do anything, although the code to get the html data does work. Any comment greatly appreciated, thanks! Martin.

    K 1 Reply Last reply
    0
    • M Martin23

      Hi, I am making an application that simply gets all the html from a webpage and filters out the data I want. The problem is that I want a progressbar to indicate it is working (using the "marquee" style). My code looks like this; Private void getWebData() { progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Value = 100; //simple code to get wepage... //simple code to filter out data I want... //put data into listbox progressBar1.Value = 0; progressBar1.Style = ProgressBarStyle.Continuous; } I thought that this would set the progressbar going, then do the work, then stop the progress bar, but instead the progress bar just doesnt do anything, although the code to get the html data does work. Any comment greatly appreciated, thanks! Martin.

      K Offline
      K Offline
      kasik
      wrote on last edited by
      #2

      Martin23 wrote:

      I thought that this would set the progressbar going, then do the work, then stop the progress bar, but instead the progress bar just doesnt do anything, although the code to get the html data does work.

      If the entire form that the progress bar is on locks up, along with the progress bar not moving (i.e. nothing is redrawn on the form), then it is probably because you are running your webpage code from the same thread. The way to get around this is to run the web code on a seperate thread (although you shouldn't update your ListBox from this new thread, as that will throw errors). Hope that helps :) Cheers, Will H

      M 1 Reply Last reply
      0
      • K kasik

        Martin23 wrote:

        I thought that this would set the progressbar going, then do the work, then stop the progress bar, but instead the progress bar just doesnt do anything, although the code to get the html data does work.

        If the entire form that the progress bar is on locks up, along with the progress bar not moving (i.e. nothing is redrawn on the form), then it is probably because you are running your webpage code from the same thread. The way to get around this is to run the web code on a seperate thread (although you shouldn't update your ListBox from this new thread, as that will throw errors). Hope that helps :) Cheers, Will H

        M Offline
        M Offline
        Martin23
        wrote on last edited by
        #3

        Yes that does help, thnaks! Further problem now is how do I stop the progress bar? because if I put the code to stop the progress bar in the new thread, then that makes the progressbar disappears altogether when the thread finishes (why is that?), and I can't put the code like this; Private void getWebData() { progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Value = 100; //start new thread to do everything progressBar1.Value = 0; progressBar1.Style = ProgressBarStyle.Continuous; } because then as you would expect it starts and stop the progress bar imidiately. I assume I have to somehow attach an event handler to the new thread so I know when it finishes? thanks Martin

        K 2 Replies Last reply
        0
        • M Martin23

          Yes that does help, thnaks! Further problem now is how do I stop the progress bar? because if I put the code to stop the progress bar in the new thread, then that makes the progressbar disappears altogether when the thread finishes (why is that?), and I can't put the code like this; Private void getWebData() { progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Value = 100; //start new thread to do everything progressBar1.Value = 0; progressBar1.Style = ProgressBarStyle.Continuous; } because then as you would expect it starts and stop the progress bar imidiately. I assume I have to somehow attach an event handler to the new thread so I know when it finishes? thanks Martin

          K Offline
          K Offline
          kasik
          wrote on last edited by
          #4

          Hmmm... Not sure. You could try an event handler, but I would take a look at this[^] article first (it explains GUI updation from different threads. I think it applies to FW v2, but I'm not sure) Cheers, Will H

          1 Reply Last reply
          0
          • M Martin23

            Yes that does help, thnaks! Further problem now is how do I stop the progress bar? because if I put the code to stop the progress bar in the new thread, then that makes the progressbar disappears altogether when the thread finishes (why is that?), and I can't put the code like this; Private void getWebData() { progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Value = 100; //start new thread to do everything progressBar1.Value = 0; progressBar1.Style = ProgressBarStyle.Continuous; } because then as you would expect it starts and stop the progress bar imidiately. I assume I have to somehow attach an event handler to the new thread so I know when it finishes? thanks Martin

            K Offline
            K Offline
            kasik
            wrote on last edited by
            #5

            Maybe you've already worked it out, but I had a play and if you stick the following code somewhere, and then call StopProgressBar() from the new thread (after all the web stuff), it should work.

            private delegate void SetProgBarDelegate();
            private void StopProgressBar()
            {
            if (this.InvokeRequired)
            {
            this.BeginInvoke(new SetProgBarDelegate(StopProgressBar));
            return;
            }
            this.progressBar1.MarqueeAnimationSpeed = 0;
            }

            Cheers, Will H

            M 1 Reply Last reply
            0
            • K kasik

              Maybe you've already worked it out, but I had a play and if you stick the following code somewhere, and then call StopProgressBar() from the new thread (after all the web stuff), it should work.

              private delegate void SetProgBarDelegate();
              private void StopProgressBar()
              {
              if (this.InvokeRequired)
              {
              this.BeginInvoke(new SetProgBarDelegate(StopProgressBar));
              return;
              }
              this.progressBar1.MarqueeAnimationSpeed = 0;
              }

              Cheers, Will H

              M Offline
              M Offline
              Martin23
              wrote on last edited by
              #6

              Wow, thanks Will, thats perfect! I'll remember to pass your kindness on to someone else! (plus I'll get a book on threading in .NET ;) ) Martin

              K 1 Reply Last reply
              0
              • M Martin23

                Wow, thanks Will, thats perfect! I'll remember to pass your kindness on to someone else! (plus I'll get a book on threading in .NET ;) ) Martin

                K Offline
                K Offline
                kasik
                wrote on last edited by
                #7

                Glad I could help :D Cheers, Will H

                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