【问题标题】:ObjectDisposedException when using IMessageFilter使用 IMessageFilter 时出现 ObjectDisposedException
【发布时间】:2016-05-18 00:14:15
【问题描述】:

我最近遇到了一种情况,我有一个要拦截和处理消息的表单。第一次打开表单时一切正常,但在关闭并再次打开后,我会得到一个 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)
    {

    }
}

【问题讨论】:

    标签: c# winforms objectdisposedexception imessagefilter


    【解决方案1】:

    一定要打电话

    Application.RemoveMessageFilter(this)
    

    处理完消息后(即关闭表单时)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多