Results 1 to 6 of 6

Thread: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar

  1. #1
    Lively Member HunterTTP's Avatar
    Join Date
    Jul 12
    Posts
    115

    Resolved [RESOLVED] VB 2010: Cross-thread problem with Progress Bar

    Alright so I finished my first program and I'm working on my second. I copied over a bunch of stuff and now the only problem I am having is this error with my progress bar.

    "Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on."

    I've fixed this before, but I can't quite remember. Here is the code it is being used by-

    Code:
    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    
            ProgressBar1.Value = Convert.ToInt32(100 * P / 2)
    
        End Sub

  2. #2
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 11
    Posts
    605

    Re: VB 2010: Cross-thread problem with Progress Bar

    Invoke the UI thread to access the progressbar properties.

    vb Code:
    1. ProgressBar1.Invoke(Sub() ProgressBar1.Value = Convert.ToInt32(100 * P / 2))
    <<<------------
    < Please rate my post if this helped you out. Any kind of thanks is gladly appreciated >



    VB Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  3. #3
    Lively Member HunterTTP's Avatar
    Join Date
    Jul 12
    Posts
    115

    Re: VB 2010: Cross-thread problem with Progress Bar

    Thanks! Although, I found the problem once I read back through my code. The report progress was set to the wrong progress change.

  4. #4
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 11
    Posts
    605

    Re: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar

    The cross thread issue has more to do with threads trying to take action on threads that aren't their own.
    <<<------------
    < Please rate my post if this helped you out. Any kind of thanks is gladly appreciated >



    VB Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  5. #5
    Lively Member HunterTTP's Avatar
    Join Date
    Jul 12
    Posts
    115

    Re: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar

    That really did help though, on a totally different part of my program xD Thanks.

  6. #6
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 11
    Posts
    605

    Re: [RESOLVED] VB 2010: Cross-thread problem with Progress Bar

    No problem, as long as you've got things figured out
    <<<------------
    < Please rate my post if this helped you out. Any kind of thanks is gladly appreciated >



    VB Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

Posting Permissions

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