Delegate.GetInvocationList Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Returns the invocation list of the delegate.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public Overridable Function GetInvocationList As Delegate()

Return Value

Type: System.Delegate()

An array of delegates representing the invocation list of the current delegate.

Each delegate in the array represents exactly one method.

The order of the delegates in the array is the same order in which the current delegate invokes the methods that those delegates represent.

The following example assigns three methods to a delegate. It then calls the GetInvocationList method to get a total count of the methods assigned to the delegate, to execute the delegates in reverse order, and to execute the methods whose name do not include the substring "File".

Imports System.IO
Imports System.Reflection
Imports System.Windows.Forms

Module Example
   Public outputMessage As Action(Of String)

   Public Sub Main()
      Dim output1 As Action(Of String) = AddressOf Console.WriteLine
      Dim output2 As Action(Of String) = AddressOf OutputToFile 
      Dim output3 As Action(Of String) = AddressOf MessageBox.Show

      outputMessage = [Delegate].Combine( { output1, output2, output3 } )
      Console.WriteLine("Invocation list has {0} methods.", 

      ' Invoke delegates normally.
      outputMessage("Hello there!")
      Console.WriteLine("Press <Enter> to continue...")

      ' Invoke each delegate in the invocation list in reverse order.
      For ctr As Integer = outputMessage.GetInvocationList().Count - 1 To 0 Step -1
          Dim outputMsg = outputMessage.GetInvocationList(ctr)
          outputMsg.DynamicInvoke("Greetings and salutations!")
      Console.WriteLine("Press <Enter> to continue...")

      ' Invoke each delegate that doesn't write to a file.
      For ctr As Integer = 0 To outputMessage.GetInvocationList().Count - 1 
         Dim outputMsg = outputMessage.GetInvocationList(ctr)
         If Not outputMsg.GetMethodInfo().Name.Contains("File") Then
            outputMsg.DynamicInvoke( { "Hi!" } )
         End If
   End Sub

   Private Sub OutputToFile(s As String)
      Dim sw As New StreamWriter(".\output.txt")
   End Sub
End Module


when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top