Threading problem

  • Thread starter Thread starter Soheil
  • Start date Start date
S

Soheil

Hi,

Can anybody tell me why this piece of code makes my app halt?
It's just a simple form with two buttons on it!
But when I remove "Button2.Show()", everything is ok!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ThreadPool.QueueUserWorkItem(AddressOf SomeThing)
End Sub

Private Sub SomeThing(ByVal state As Object)
Button1.Hide()
Button2.Show()
End Sub

Regards,
Soheil
 
* "Soheil said:
Can anybody tell me why this piece of code makes my app halt?
It's just a simple form with two buttons on it!
But when I remove "Button2.Show()", everything is ok!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ThreadPool.QueueUserWorkItem(AddressOf SomeThing)
End Sub

Private Sub SomeThing(ByVal state As Object)
Button1.Hide()
Button2.Show()
End Sub

You cannot access instance members of Windows Forms controls from
another thread because they are not thread safe. Instead, use
'Control.Invoke' to invoke the method.
 
Back
Top