What is the C ++ / CLI syntax for event subscription?

I am updating the old managed C ++ code with the following lines:

instanceOfEventSource->add_OnMyEvent( 
    new EventSource::MyEventHandlerDelegate(this, MyEventHandlerMethod) );

Where

  • EventSource is a class that publishes events
  • instanceOfEventSource is an instance of this class
  • EventSource :: MyEventHandlerDelegate is the type of delegate for the event
  • MyEventHandlerMethod is a (non-static) method in the current class (from which "this" is an instance) with signatures matching EventSource :: MyEventHandlerDelegate

What is the correct syntax for this in C ++ / CLI?

+5
source share
2 answers

#, , += , :

instanceOfEventSource.MyEvent +=
    gcnew EventSource::MyEventHandlerDelegate(this, &MyClass::MyEventHandlerMethod);

. , #, , .

+6

, , . , , . , .

:

System::EventHandler^ h = gcnew System::EventHandler(&MyClass::MyStaticCallbackMethod);
+1

All Articles