Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Progress bar not updating when BackgroundWorker ReportProgress from module

$
0
0
Consider the code below for a simple form with a progress bar, a button, and BGW is a BackgroundWorker with Modifiers = Public. This works but if I change blnRunInModule to true it doesn’t update. Yet the PerformStep is being executed as is apparent by the Debug.WriteLine showing the value increasing. What am I doing wrong?
vb.net Code:
  1. Public Class Form1
  2.     Private Sub Button1_Click() Handles Button1.Click
  3.         BGW.RunWorkerAsync()
  4.     End Sub
  5.     Private Sub BGW_DoWork() Handles BGW.DoWork
  6.         Dim blnRunInModule As Boolean = False
  7.         For intCount As Integer = 1 To 10
  8.             If blnRunInModule Then
  9.                 Module1.MySub(intCount)
  10.             Else
  11.                 BGW.ReportProgress(intCount)
  12.             End If
  13.             System.Threading.Thread.Sleep(1000)
  14.         Next
  15.     End Sub
  16.     Private Sub BGW_ProgressChanged() Handles BGW.ProgressChanged
  17.         ProgressBar1.PerformStep()
  18.         Debug.WriteLine("Step executed. Value = " & ProgressBar1.Value)
  19.     End Sub
  20. End Class
vb.net Code:
  1. Module Module1
  2.     Sub MySub(intCount As Integer)
  3.         Form1.BGW.ReportProgress(intCount)
  4.     End Sub
  5. End Module

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>