Halting and Debugging thread?

I have three data processing routines which I want to run in threads so that they don’t clog up the UI. How can I halt execution of thread until prior thread completes successfully. 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 

  'Link tables. 
  'Spin off a new thread. 
  t1 = New Thread(New ThreadStart(AddressOf CreateLinks)) 
  t1.IsBackground = True 
  t1.Start() 

  Select Case True 

    Case optRawFigures.Checked 
      'Spin off a new thread. 
      t2 = New Thread(New ThreadStart(AddressOf GetFigures)) 
      t2.IsBackground = True 
      t2.Start() 

    Case optAverage.Checked 
      'Spin off a new thread. 
      t3 = New Thread(New ThreadStart(AddressOf CalculateFigures)) 
      t3.IsBackground = True 
      t3.Start() 

  End Select 

End Sub 

Apparently thread t1 is executed on button click along with one of the threads from Select Case. This leads to error because tables need to be linked before any data processing job can be done. 

I want t1 to execute and when it is completed successfully it should execute Select Case. 

Also, how can I debug the routine which runs off a thread. 

Thanks 


Answer this question

Halting and Debugging thread?

  • Thomas Hecht

    you can also use a boolean shared/static var to determine if they're done.. just remember to have a lock in place.  Depends on what you're more comfortable using.
  • Lishen

    Use thread.Join() to wait until that thread has completed.

    I don't know of any way to debug inside a thread. I always write a little test application that calls the faulty method without threading - which might not always be possible, especially if the error is caused by a race condition or something like that.

  • Halting and Debugging thread?