title: Visual Basic.NET: how to create a thread to update the UI
body: <p>The usual VB way to handle a computationally heavy task is to put it in a background worker thread, while the main thread keeps handling the UI.</p>
  
  <p>Say for whatever reason I needed to do this the other way around:  the main thread doing the grunt work and the background one updating the UI.</p>
  
  <p>Here's what I have so far.  The only problem is, while the UI window (Form1) does get redrawn, you can't interact with it, not even move or resize it (the mouse cursor turns to hourglass and won't click).</p>
  
  <pre><code>Public Class ProgressDisplay
  
  Private trd As Thread
  
      Public Sub New()
          trd = New Thread(AddressOf threadtask)
          trd.Start()
      End Sub
  
      Private Sub threadtask()
          Dim f1 As Form1
          f1 = New Form1
          f1.Show()
          Do
              f1.Update()
              Thread.Sleep(100)
          Loop
      End Sub
  
  End Class
  </code></pre>
  
  <p>Edit:  Ideally I need to present an interface like this to the client</p>
  
  <pre><code>Public Class ProgressDisplay
      Public Sub New()
      Public Sub Update(byval progress as int)
  End Class
  </code></pre>
  
  <p>The client will call it like this (actually in unmanaged c++ over COM but you get the picture):</p>
  
  <pre><code>Dim prog = new ProgressDisplay()
  DoLotsOfWork(addressof prog.update) ' DoLotsOfWork method takes a callback argument to keep client informed of progress
  </code></pre>