delegates and events

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

is it possible to know what event-handlers are 'connected' to an event ?

(In the same style as you have access to the InvocationList with delegates.)


Thnx
Chris
 
Chris said:
Hi,

is it possible to know what event-handlers are 'connected' to an event ?

(In the same style as you have access to the InvocationList with
delegates.)


Hi Chris,

Will this work for you?

using System;

class Test
{
public event EventHandler myEvent;

public static void Main()
{
Test test = new Test();

test.myEvent +=new EventHandler(test_myEvent);

Delegate[] myDelegates = test.myEvent.GetInvocationList();

foreach (Delegate del in myDelegates)
{
Console.WriteLine("Method: {0}", del.Method.Name);
}

Console.ReadLine();
}

private static void test_myEvent(object sender, EventArgs e)
{
Console.WriteLine("MyEvent");
}
}

Joe
 
Back
Top