MethodInvoker Delegate
Represents a delegate that can execute any method in managed code that is declared void and takes no parameters.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
MethodInvoker provides a simple delegate that is used to invoke a method with a void parameter list. This delegate can be used when making calls to a control's Invoke method, or when you need a simple delegate but do not want to define one yourself.
The following code example demonstrates how to use a MethodInvoker to call a method that updates the title bar of the application form.
Partial Public Class Form1 Inherits System.Windows.Forms.Form Public Sub New() ' Create a timer that will call the ShowTime method every second. Dim timer As System.Threading.Timer = _ New System.Threading.Timer(AddressOf ShowTime, Nothing, 0, 1000) End Sub Sub ShowTime(ByVal x As Object) ' Don't do anything if the form's handle hasn't been created ' or the form has been disposed. If (Not Me.IsHandleCreated And Not Me.IsDisposed) Then Return ' Create the method invoker. ' The method body shows the current time in the forms title bar. Dim mi As MethodInvoker = AddressOf UpdateFormText Me.Invoke(mi) End Sub Sub UpdateFormText() Me.Text = DateTime.Now.ToLongTimeString() End Sub End Class
The following code example demonstrates how to use the MethodInvoker delegate to synchronize a call to a control's thread.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.