Tech Off Post

Single Post Permalink

View Thread: I was told today to not worry cross-thread execution when...
  • User profile image
    gadget

    I check inside the method to see if an invoke is required. If so have the delegate make a recursive call to the method, otherwise perform the action.

    This is in vb but should be clear.

     Public Sub ReadKeyboard()
            If Me.InvokeRequired Then
                Dim x As Action = AddressOf ReadKeyboard
                Me.Invoke(x)
            Else
                me.Text = "Keyboard acquired"
            End If
     End Sub

    Check out the invokerequired property of the control class.
    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx