我有一个活动
public event EventHandler<MyEventArgs> OnMyEvent;
我想在我的方法中订阅此事件,拦截触发该事件的事件并取消订阅该事件。
该代码不起作用...
private string InterceptMessage()
{
EventHandler<MyEventArgs> handler = null;
string message_intercepted = null;
handler = (sender, e) =>
{
message_intercepted = e.Message;
OnMyEvent -= handler;
};
OnMyEvent += handler;
return message_intercepted;
}