title: VB.net 2010 backgroundworker updating form progressbar
body: <p>Trying to understand background workers :)</p>
  
  <pre><code>Imports System.Threading
  Imports System
  Imports System.IO
  Imports System.Windows.Forms
  Imports System.ComponentModel
  Imports System.Text.RegularExpressions
  Imports System.Text
  Imports System.Diagnostics
  Imports System.Drawing
  
  
  Public Class CLViewForm
  
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      BackgroundWorker1.RunWorkerAsync()
  End Sub
  
  
  Function SystemLoads()
      Dim PCV As Integer = Convert.ToDecimal(PerformanceCounter1.NextValue())
      Me.Label5.Text = PCV &amp; " %"
      Me.ProgressBar1.Minimum = 0
      Me.ProgressBar1.Maximum = 100
      Me.ProgressBar1.Step = 1
      Me.ProgressBar1.Value = PCV
      Me.Label6.Text = Now.ToLongTimeString
      Return 0
  End Function
  
  Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
      Me.Invoke(SystemLoads())
      End Sub
  End Class
  </code></pre>
  
  <p>The basic gist of what I am trying to do is just load a background worker that updates 3 things on the primary form
  a progressbar that shows current system load
  a text label that shows the load by percent
  and a clock</p>
  
  <p>I know I can do all this with a simple timer, but when I go to add my other timers it tends to make the form all kinds of sluggish so I wish to learn how to shoot most of these things I want to do into a background thread.</p>
  
  <p>I am new to all this so I do not know how to call these things and be thread safe about it and as such I get an error [of course, which is why I am here asking :)] that says 
  "vb.net cross-thread operation not valid control 'progressbar1'  accessed from a thread other than which is it called"</p>
  
  <p>or something to that effect.</p>
  
  <p>Using the code sample I supplied how can I make the background thread update the form's progress bar and % label?</p>
  
  <p>TIA</p>