从C ++ \ CLI订阅C#EventHandler事件

时间:2015-03-13 12:54:09

标签: c# events delegates c++-cli

我有以下C#代码,它使用通用的EventHandler委托:

public class EventSource
{
    public event EventHandler<MyEventArgs> SomethingHappened;
}

我尝试从C ++ \ CLI代码订阅此事件:

public ref class EventSink
{
public:
    void Handler(Object^ sender, MyEventArgs^ args) 
    {
         DoSomthing(args);
    }
};

class Manager
{
private:
    gcroot<EventSource^> _eventSource;
    gcroot<EventSink^> _eventSink;

public:
    Manager()
    {
        _eventSource = gcnew EventSource();
        _eventSink = gcnew EventSink();

        _eventSource->SomethingHappened += // What do I put here?
    }
}

如何实例化EventHandler委托以传递给_eventSource->SomethingHappened.Add属性?

0 个答案:

没有答案