我最近有一种情况,我有一个表格,我正在拦截和处理消息。第一次打开表单时一切正常,但在关闭并再次打开之后,我会得到一个ObjectDisposedException。
我终于想通了我需要打电话
Application.RemoveMessageFilter(this)
关闭表单时,否则,它会继续尝试处理已关闭表单的消息。我没有在这里看到任何解决这个问题的答案/答案,所以我想添加它以防其他人遇到同样的问题。
此外,MSDN上的示例也没有显示删除邮件过滤器。
public partial class Template_Editor : Form, IMessageFilter
{
public Template_Editor(ICollection<Vendor> vendorList)
{
InitializeComponent();
Application.AddMessageFilter(this);
}
public bool PreFilterMessage(ref Message m)
{
}
}
答案 0 :(得分:0)
请务必致电
Application.RemoveMessageFilter(this)
完成处理消息后(即关闭表单时)