我加入处理程序申请:如何从应用程序中删除事件处理程序?
Application.ThreadException += (sender, a) => UnhandledExceptionsHelper.ApplicationOnThreadException(a, null);
这个我想添加另一个处理程序
Application.ThreadException += (sender, a) => UnhandledExceptionsHelper.ApplicationOnThreadException(a, param);
如何删除以前的处理程序之后?
当我删除控制处理程序,我只是用:
public void RemoveOnThreadException(SimpleButton b)
{
FieldInfo f1 = typeof(Control).GetField("EventClick",
BindingFlags.Static | BindingFlags.NonPublic);
object obj = f1.GetValue(b);
PropertyInfo pi = b.GetType().GetProperty("Events",
BindingFlags.NonPublic | BindingFlags.Instance);
EventHandlerList list = (EventHandlerList)pi.GetValue(b, null);
list.RemoveHandler(obj, list[obj]);
}
我怎样才能做同样的应用程序和应用程序域?
@Andrey有我尝试用Button.Click:
public TestForm()
{
InitializeComponent();
simpleButton1.Click += (sender, a) => simpleButton1_Click(sender,a);
simpleButton1.Click -= simpleButton1_Click;
simpleButton1.Click += (sender, a) => simpleButton1_Click(sender, a);
}
private void simpleButton1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hi");
}
,当我点击按钮,我得到两个消息。
[C#中取消匿名方法(可能的重复http://stackoverflow.com/questions/183367/unsubscribe-anonymous-方法在C - 尖锐) – Pasick
两个问题:1)当你想添加另一个处理程序?即在一些用户操作之后,或者在第一个处理程序被触发后2)你在哪里得到第二个处理程序的'param'? –
@Pasick这不是100%重复,因为有一些关于Application.ThreadException的具体细节 – Andrey