.NET 4.0 - AccessViolationException和的WndProc [英] .NET 4.0 - AccessViolationException and WndProc

查看:153
本文介绍了.NET 4.0 - AccessViolationException和的WndProc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个code片断:

I have this code snippet:

internal class MTool : NativeWindow
{
    private const int WM_LBUTTONDOWN = 0x0201;
    public event TipDeactivateEventHandler Deactivate;

    protected override void WndProc(ref System.Windows.Forms.Message m)
    {           
        if( m.Msg == WM_LBUTTONDOWN )
        {
            if( this.Deactivate != null)
            {
                this.Deactivate();
            }
        }

        base.WndProc(ref m);
    }
}

当我运行我的程序,我碰到一个AccessViolationException错误在该行 base.WndProc(REF米); ,我不知道为什么。

When I run my program I get an AccessViolationException error at the line base.WndProc(ref m); and I don't know why.

显然,这是移植了从.NET 2.0到4.0,我的理论是,有可能是已经到位压倒一切的WndProc中使用的替代方法。这是这样吗?如果不是,为什么我会收到此异常?

Apparently this was ported over from .NET 2.0 to 4.0 and my theory is that there may be an alternate method used now in place of overriding WndProc. Is this case? If not why am I getting this exception?

推荐答案

我固定它通过将上述方法这个属性:

I fixed it by adding this attribute above the method:

[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]

然后围绕其中的例外与一个try / catch出现就行了。我发现这个信息<一个href="http://dotnetslackers.com/articles/net/All-about-Corrupted-State-Exceptions-in-NET4.aspx">here.

这篇关于.NET 4.0 - AccessViolationException和的WndProc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆