Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:27:23+00:00 2026-06-13T12:27:23+00:00

I am stuck updating a progressbar from a different thread. I did get it

  • 0

I am stuck updating a progressbar from a different thread.
I did get it running in the simplest way, but then cleaning the code gets me stuck.

My testing code looks like all the examples on the web related to backgroundworker and BeginInvoke.

FormP is the Progressbar-Form.
This works:

Public Class Form1
Private Delegate Sub delegate_ProgressUpdate(ByVal paramValue As Integer,
  ByVal paramMax As Integer)

Private Sub Button1_Click(sender As System.Object,
  e As System.EventArgs) Handles Button1.Click
    ' Test 01:
    ' Show Progressbar via BGW
    ' All functions are within Form1
    Dim bgw As New BackgroundWorker()
    AddHandler bgw.DoWork, AddressOf BGW_Sample01_DoWork

    FormP.Show(Me)
    bgw.RunWorkerAsync()
End Sub

Private Sub invokeMe_ProgressUpdate(ByVal paramValue As Integer, ByVal paramMax As Integer)
    FormP.ProgressBar1.Maximum = paramMax
    FormP.ProgressBar1.Value = paramValue
    FormP.ProgressBar1.Update()
End Sub

Private Sub BGW_Sample01_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
    For i As Integer = 1 To 10
        Threading.Thread.Sleep(500) ' Test delay
        Me.BeginInvoke(New delegate_ProgressUpdate(AddressOf invokeMe_ProgressUpdate),
                       i, 10)
    Next
    MessageBox.Show("Fertig")
End Sub

If I try to make things work more orderly encapsulated in FormP, it doesn’t work.

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Dim bgw As New BackgroundWorker
    AddHandler bgw.DoWork, AddressOf BGW_Sample02_DoWork
    FormP.Show(Me)
    bgw.RunWorkerAsync()
End Sub

Private Sub BGW_Sample02_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
    For i As Integer = 1 To 10
        Threading.Thread.Sleep(500)
        FormP.SetProgress(i, 10)
    Next
    MessageBox.Show("Fertig")
End Sub


' ########## FormP #################

Public Class FormP

Private Delegate Sub delegate_ProgressUpdate(ByVal value As Integer, ByVal maximum As Integer)

Public Sub SetProgress(ByVal paramValue As Integer, ByVal paramMaximum As Integer)
    If Me.InvokeRequired Then
        Me.Invoke(New delegate_ProgressUpdate(AddressOf Me.SetProgress), paramValue, paramMaximum)
    Else
        Me.ProgressBar1.Maximum = paramMaximum
        Me.ProgressBar1.Value = paramValue
        Me.ProgressBar1.Update()
    End If
End Sub

End Class

FormP does not freeze, but UI is not updated.
Actually Me.InvokeRequired is false and I think that’s where I begin to miss some important parts.
I tried Form1.InvokeRequired here, but it’s false as well.
My understanding is: the calling thread here is the bgw thread, no matter in what class the code is that this thread calls…
That seems not to be it?

Thanks for any thoughts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:27:24+00:00Added an answer on June 13, 2026 at 12:27 pm

    What worked eventually:

    Private frmP As FormP
    
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim bgw As New BackgroundWorker
        If Me.frmP IsNot Nothing AndAlso Me.frmP.Visible Then Return
        Me.frmP = New FormP
        Me.frmP.Show(Me)
        AddHandler bgw.DoWork, AddressOf BGW_Sample02_DoWork
        bgw.RunWorkerAsync(New Object() {Me.frmP})
    End Sub
    
    Private Sub BGW_Sample02_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
        Dim objFrmP As FormP = DirectCast(e.Argument(0), FormP)
        For i As Integer = 1 To 10
            objFrmP.setProgress(i, 10)
            Threading.Thread.Sleep(500)
        Next
        MessageBox.Show("Finished")
    End Sub
    

    The Progress-Dialog-Code in FormP:

    Public Sub setProgress(paramValue As Integer, paramMaximum As Integer)
        If Me.InvokeRequired Then
            ' defining a delegate type is not really necessary
            Me.Invoke(Sub() Me.setProgress(paramValue, paramMaximum))
        Else
            Me.ProgressBar1.Maximum = paramMaximum
            Me.ProgressBar1.Value = paramValue
            Me.ProgressBar1.Update()
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i m using Abraham twitteroauth class for updating the twitter status, but i stuck
I am updating an old piece of C++ code and am stuck on a
I'm stuck here: Installing/Updating AsseticBundle 9c1b7269a4517d1ae94af2dc0d6d6fc4b31e6c10 HEAD is now at 41b5913 Merge pull request
Im stuck with this little project in C# but basically my problem is this:
Im stuck in Excel 2007, running a query, it worked until I wanted to
i cant seem to get any of the didenterregion/didexitregion delegates firing , been stuck
Got stuck and need some help, This should be relatively simple but it's been
I'm stuck on this code and can't figure out where I need to go.
I am stuck in a particular scenario. I need to get my widget updated
I have a really simple app I've built using RoR but I'm stuck modifying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.