[2005] ProgressBar in new thread on From2
I have a new thread that opens up when I hit a query button. I'm not sure I am opening the "Form2" correctly because I do not see it when running tests however, the debug doesn't pick anything up. Here is the code:
vb Code:
Public Sub ShowProgBar()
Dim form2PB As Form = mywindowsapp1.Form2
form2PB.Show()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'validate the text fields
'some code that does some stuff.....
Dim thread1 As System.Threading.Thread
thread1 = New System.Threading.Thread(AddressOf ShowProgBar)
thread1.Start()
'more code that does some stuff
'processes running while progress bar should be displaying
MessageBox.Show("Processes Complete")
Application.Exit()
'this is also where the progress bar thread should terminate
End Sub
I am wondering why I am not seeing Form2 (containing my progressbar) during this.
Thanks
Re: [2005] ProgressBar in new thread on From2
You are going about it the wrong way. You should not start the thread and then create the form in that thread because you want all your controls created on the same main thread. What you should be doing is creating the form first, then starting the thread from that form. Now the form and its controls have been created on the same thread as the rest of the UI and you do only the background processing in the background thread.
I'd also suggest using a BackgroundWorker to make updating the ProgressBar easier.
http://www.vbforums.com/showthread.php?t=471889