Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.80 KB | None | 0 0
  1. <Extension(), DebuggerHidden()>
  2. Public Sub InvokeIfRequired(control As Control, action As MethodInvoker)
  3.     If control.InvokeRequired Then control.Invoke(action) Else action()
  4. End Sub
  5. ' No parameters
  6. <Extension(), DebuggerHidden()>
  7. Public Function InvokeIfRequired(Of TR)(control As Control, func As Func(Of TR)) As TR
  8.     If control.InvokeRequired Then
  9.         Return control.Invoke(func)
  10.     Else
  11.         Return func.Invoke()
  12.     End If
  13. End Function
  14. ' One parameter
  15. <Extension(), DebuggerHidden()>
  16. Public Function InvokeIfRequired(Of T1, TR)(control As Control, func As Func(Of T1, TR), arg1 As T1) As TR
  17.     If control.InvokeRequired Then
  18.         Return CType(control.Invoke(func, arg1), TR)
  19.     Else
  20.         Return func.Invoke(arg1)
  21.     End If
  22. End Function
  23. ' n parameters can be extrapolated...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement