c# Event移除所有绑定,注销事件绑定

时间:2021-08-25 08:29:57   收藏:0   阅读:21

public delegate void d_ReadyToPrint(byte[] bytes);
public event d_ReadyToPrint ReadyToPrint;

public void ClearAllEvent()
{
if (ReadyToPrint == null) return;
Delegate[] dels = ReadyToPrint.GetInvocationList();
foreach (Delegate del in dels)
{
object delObj = del.GetType().GetProperty("Method").GetValue(del, null);
string funcName = (string)delObj.GetType().GetProperty("Name").GetValue(delObj, null);
Console.WriteLine(funcName);
ReadyToPrint -= del as d_ReadyToPrint;
}
}

原文:https://www.cnblogs.com/xhztech/p/15182868.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!