title: Attempting - Multithreading - in VB.net Windows Forms
body: <p>For a while now i have been using this code: </p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      Dim t2 As New Threading.Thread(AddressOf SetLabelText2)
      t2.IsBackground = True
      t2.Start()
  End Sub
  
  Delegate Sub UpdateDelegate()
  
  Private Sub SetLabelText2()
      If InvokeRequired Then
          Invoke(New UpdateDelegate(AddressOf SetLabelText2))
      Else
          For i = 1 To 110
              Label2.Text = Text
              Threading.Thread.Sleep(200)
          Next
      End If
  End Sub
  </code></pre>
  
  <p>This code runs fine, except its not Multithreading my Application and puts it into a Unresponsive State.</p>
  
  <p>My Question is simple, 
  1.How can i fix this ( The application I will be using will have SEVERAL Function calls within </p>
  
  <pre class="lang-vb prettyprint-override"><code>If InvokeRequired Then
  
      Invoke(New UpdateDelegate(AddressOf SetLabelText2))
  
  Else
  
     FunctionCall1()
  
     FunctionCall2()
  
     FunctionCall3()
  
  End If
  </code></pre>
  
  <p>they all work and take ahold of my UI Thread.</p>
  
  <p>I have been searching for quite some time now, any help is appreciated.</p>
  
  <p>-Edit-
  Also having issues while in a thread to read information from a form ... :) thanks for the help so far</p>
  
  <p>EDIT --- </p>
  
  <p>Ok, i have change my Code around to look like </p>
  
  <pre class="lang-vb prettyprint-override"><code>Delegate Sub setForm1PrgBarPerformStepdelegate(s As Integer) 
      Private Sub setForm1PrgBarPerformStep(ByVal s As Integer)
          If Form1.ProgressBar1.InvokeRequired Then
              Dim d As New setForm1lblAlltextdelegate(AddressOf setForm1PrgBarPerformStep)
              Form1.Invoke(d, New Object() {s})
          Else
              If s = 1 Then
              Form1.ProgressBar1.PerformStep()
          Else
  
          End If
      End If
  End Sub
  </code></pre>
  
  <p>This piece of code is being called with setForm1PrgBarPerformStep(1) ' or 0 </p>
  
  <p>Wich is called by my thread, ( It works ( the threading part - witch is awesome btw ), with the minor flaw of NOT doing the Perform Step - or any other UI changes I Code in the Private Sub setForm1PrgBarPerformStep() </p>
  
  <p>Is there a good reason for this?</p>