Results 1 to 9 of 9

Thread: Progress Bar issue?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    56

    Progress Bar issue?

    So, I did some research, and I believe my issue is something to do with the GUI update. The thing is, I know nothing about GUI updateing, and every example that iv seen look extremly next level, and I dont understand it (normally when I copy and paste working code online, I have to change up a few things to get it to work for my program specifically, if I dont understand it or how it works, it makes it extrmely more complicated to find an answer) so sorry if this has already been posted.

    So, I have 2 forms (well technecally 3, but the first one just opens up the 2nd form)
    So, what I am trying to do is use a background worker from Form3 to update a progress bar on Form2. It works, but it doesnt at the same time.
    I have used a message box to tell me the value every time it updates using:
    Form2.ProgressBar1.Value += 1
    MessageBox.Show (Form2.ProgressBar1.Value)

    It keeps on itterating correctly
    But the progress bar doesnt actually show anything, the bar doesnt actually move to the value it is set to.
    So for example, if I where to programically set it to 90, it would still look like its at 0. BUT if I leave the itteration and it passes 100 (so 101) the program will crash and say that its out of the maximum range (obviously)... So, the value part is working, but the actual bar, isnt moving.

    Why might this be?
    And how might I fix this problem in a simple solution?

    I know its a bad idea to use a background worker, but my program is responding to a download/upload feature, so the user will still need the program to respond, and update showing everything they need to know (like time, progress, files left, folders left, transfer rate, etc etc...)
    This is why I am using a background worker instead of a timer, because a timer, the program wont be able to respond, and I have found that as the only and fastest method to use.

    If you need any more information, I am happy to provide my full programs code for the background worker.

    Thank you in advance for any help.

    Oh and by the way, I could itterate the program properly if I where to use the same background worker with the same settings, and the same progress bar with the same settings on Form3

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Progress Bar issue?

    Try doing this, replace MessageBox.Show with Console.WriteLine. This will prevent a messagebox from popping up every single time the ProgressBar's value is updated. The value would be seen in the Output window whenever you call Console.WriteLine; you can bring that up by going to Debug > Windows > Output. As for the issue try changing your code to this:

    Code:
    If Form2.ProgressBar1.Value < Form2.ProgressBar1.Maximum Then
        Form2.ProgressBar.Increment(1)
        Form2.ProgressBar.Invalidate()
        Console.WriteLine(Form2.ProgressBar1.Value.ToString)
    End If
    The first line is to make sure that we're still within range. The second line is to add 1 to the ProgressBar's value. The third line is to 'refresh' the GUI of the ProgressBar. The fourth line is to keep track of the ProgressBar's value. I didn't test it, however it should work.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    56

    Re: Progress Bar issue?

    The code did work, the progress bars value is incrementing, but the actual progress bars visual progression is still not visible. I still dont see it going up.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Progress Bar issue?

    How are you showing Form2 initially? I think I know what the problem is, but it depends on the answer.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    56

    Re: Progress Bar issue?

    Quote Originally Posted by techgnome View Post
    How are you showing Form2 initially? I think I know what the problem is, but it depends on the answer.


    -tg
    From Form1, there is a regular button, on the click event, all it does is:
    Form2.show()

    There isnt any timers or background workers on Form1

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Progress Bar issue?

    I'm personally not able to reproduce the problem, but then again I'm not using a BackgroundWorker as this would cause some cross threading issues.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    56

    Re: Progress Bar issue?

    Well, on Form 2 and 3, I have the illegal cross thread false before calling the async. It seemed to do what I wanted.

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Progress Bar issue?

    I'm thinking that's is what is probably causing the problem. In fact, I'll test it... yeah that it's exactly what is causing the problem as I'm now able to reproduce it. You aren't suppose to update controls in any thread other than the GUI thread. In fact I've never done it before so I'll have to bow out.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    56

    Re: Progress Bar issue?

    Quote Originally Posted by dday9 View Post
    I'm thinking that's is what is probably causing the problem. In fact, I'll test it... yeah that it's exactly what is causing the problem as I'm now able to reproduce it. You aren't suppose to update controls in any thread other than the GUI thread. In fact I've never done it before so I'll have to bow out.
    Oh, I see... Would putting the increment code in a public function in Form2 then call it in Form3's background worker work?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width