title: Updating label from module in another thread
body: <p>I'm trying to update a label which is running in the UI thread from a Module... my code works fine if its within the Main Form but I'd like to try and keep my code tidy by not having it all within the Main Form and splitting it out into Modules.</p>
  
  <p>So if I have the below in my Main Form it works:</p>
  
  <pre><code>Private threadingExecuteManualScan As Thread
  
  Public Sub toolStripItem_Run_Manual_Scan_Click(sender As Object, e As EventArgs) Handles toolStripItem_Run_Manual_Scan.Click
  
          threadingExecuteManualScan = New Thread(AddressOf executeManualScanThread)
          threadingExecuteManualScan.IsBackground = True
          threadingExecuteManualScan.Start()
  
  End Sub
  
  Delegate Sub SetTextDelegate(ByVal textString As String)
  
  Private Sub updateTextBox(ByVal stringValue As String)
  
          Dim textDelegate As New SetTextDelegate(AddressOf updateTextBox)
          form_Main.BeginInvoke(textDelegate, stringValue)
  
  End Sub
  
  Public Sub executeManualScanThread()
  
      updateTextBox("Update Label With This String")
  
  End Sub
  </code></pre>
  
  <p>I'd like to move all of it to a Module except for:</p>
  
  <pre><code>Public Sub toolStripItem_Run_Manual_Scan_Click(sender As Object, e As EventArgs) Handles toolStripItem_Run_Manual_Scan.Click
  
          threadingExecuteManualScan = New Thread(AddressOf executeManualScanThread)
          threadingExecuteManualScan.IsBackground = True
          threadingExecuteManualScan.Start()
  
  End Sub
  </code></pre>
  
  <p>But when I do the Invoke.Required never returns a true value which then doesn't update my label on my Main Form.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks</p>
  
  <p>Ben</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>My Main Form Contains this:</p>
  
  <pre><code>Public Class form_Main
  
  Delegate Sub SetTextDelegate(ByVal args As String)
  Private threadingExecuteManualScan As Thread
  
  Public Sub toolStripItem_Run_Manual_Scan_Click(sender As Object, e As EventArgs) Handles toolStripItem_Run_Manual_Scan.Click
  
          threadingExecuteManualScan = New Thread(AddressOf executeManualScanThread)
          threadingExecuteManualScan.IsBackground = True
          threadingExecuteManualScan.Start()
  
  End Sub
  
  Public Sub updateTextBox(ByVal stringValue As String)
  
          Dim textDelegate As New SetTextDelegate(AddressOf updateTextBox)
          me.BeginInvoke(textDelegate, stringValue)
  
  End Sub
  
  End Class
  </code></pre>
  
  <p>And My Module:</p>
  
  <pre><code>Module module_Helper_Threading
  
  Public Sub executeManualScanThread()
  
          'Some Database Work
          form_Main.SetTextBoxInfo("Report Back - Step 1")
          'Some More Database Work
          form_Main.SetTextBoxInfo("Report Back - Step 2")
          'etc
  
  End Sub
  
  End Module
  </code></pre>
  
  <p>This however causes an error:</p>
  
  <pre><code>Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
  </code></pre>