G
Guest
I have encountered an odd behavior when using Me.Invoke and any help would
be great. I am using a standard Me.InvokeRequired followed be a Me.Invoke to
make sure a method runs on the UI thread. This logic has worked for me
countless times but for some reason I have a problem with it in one
circumstance. The Me.Invoke is called but it does not create the delegate on
the UI thread. Instead it creates the delegate on the same thread which then
gets caught by the Me.InvokeRequired which call Me.Invoke and this continues
until I get a stack overflow. So my question is what would cause Me.Invoke to
not use the UI thread but instead the thread that it is currently on? Below
is a code snippet....
Private Delegate Sub SetButtonDelegate(ByVal Value As Boolean)
Private Sub SetButton(ByVal Value As Boolean)
If Me.InvokeRequired Then
Dim newDelegate As New SetButtonDelegate(AddressOf SetButton)
Me.Invoke(newDelegate, New Object() {Value})
Else
Mylabel.Enabled = Value
Mybutton.Enabled = Value
End If
End Sub
Thanks
Madison
be great. I am using a standard Me.InvokeRequired followed be a Me.Invoke to
make sure a method runs on the UI thread. This logic has worked for me
countless times but for some reason I have a problem with it in one
circumstance. The Me.Invoke is called but it does not create the delegate on
the UI thread. Instead it creates the delegate on the same thread which then
gets caught by the Me.InvokeRequired which call Me.Invoke and this continues
until I get a stack overflow. So my question is what would cause Me.Invoke to
not use the UI thread but instead the thread that it is currently on? Below
is a code snippet....
Private Delegate Sub SetButtonDelegate(ByVal Value As Boolean)
Private Sub SetButton(ByVal Value As Boolean)
If Me.InvokeRequired Then
Dim newDelegate As New SetButtonDelegate(AddressOf SetButton)
Me.Invoke(newDelegate, New Object() {Value})
Else
Mylabel.Enabled = Value
Mybutton.Enabled = Value
End If
End Sub
Thanks
Madison