Faire des appels thread-safe en vb.net

- 1 min
  Public Sub InvokeIfRequired(ByVal method As Action)
    If Me.InvokeRequired = True Then '"Me" being the current form.
      Me.Invoke(Sub() InvokeIfRequired(method)) 'Invoke this method to make it thread-safe.
    Else
      method.Invoke() 'Execute the specified method.
    End If
  End Sub
  InvokeIfRequired(AddressOf HideWindow) 'Va appeller la fonction HideWindow
  InvokeIfRequired(Sub() Me.Visible = True) 'Va rendre la fenêtre visible
  InvokeIfRequired(Sub() Me.WindowState = FormWindowState.Normal) ' Va régler le paramètre Me.WindowState sur Normal
Jeremy Montesinos

Jeremy Montesinos

Amoureux de nouvelles technologies, de Kung Fu et de nouilles

rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora code gitlab