无法捕获的 AccessViolationException [英] Uncatchable AccesViolationException

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

问题描述

我快要绝望了.我正在使用 C# 和相当多的 p/Invoking 为 Windows Mobile 6.1 开发现场服务应用程序.(我想我引用了大约 50 个本机函数)

I'm getting close to desperate.. I am developing a field service application for Windows Mobile 6.1 using C# and quite some p/Invoking. (I think I'm referencing about 50 native functions)

在正常情况下,这没有任何问题,但是当我开始强调 GC 时,我收到了一个令人讨厌的 0xC0000005 错误,似乎无法捕捉.在我的测试中,我正在快速关闭和打开一个对话框表单(该表单确实使用了本机函数,但为了测试我将这些注释掉了),过了一会儿 Windows Mobile 错误报告器过来告诉我有一个致命的我的应用程序出错.

On normal circumstances this goes without any problem, but when i start stressing the GC i'm getting a nasty 0xC0000005 error witch seems uncatchable. In my test i'm rapidly closing and opening a dialog form (the form did make use of native functions, but for testing i commented these out) and after a while the Windows Mobile error reporter comes around to tell me that there was an fatal error in my application.

我的代码在 Application.Run(masterForm); 周围使用 try-catch 并挂钩到 CurrentDomain.UnhandledException 事件,但应用程序仍然崩溃.即使我附加了调试器,Visual Studio 也会在发生异常时告诉我与设备的远程连接已丢失"..

My code uses a try-catch around the Application.Run(masterForm); and hooks into the CurrentDomain.UnhandledException event, but the application still crashes. Even when i attach the debugger, visual studio just tells me "The remote connection to the device has been lost" when the exception occurs..

由于我在托管环境中没有成功捕获异常,所以我试图从 Error Reporter 日志文件中弄明白.但这没有任何意义,关于错误的唯一一致是它发生的应用程序.

Since I didn't succeed to catch the exception in the managed environment, I tried to make sense out of the Error Reporter log file. But this doesn't make any sense, the only consistent this about the error is the application where it occurs in.

应用程序发生的线程是我不知道的,错误发生的模块不时不同(我见过我的application.exe、WS2.dll、netcfagl3_5.dll和mscoree3_5.dll),甚至错误代码并不总是相同的.(大部分时间是 0xC0000005,但我也看到了 0X80000002 错误,这是第一个字节的警告?)

The thread where the application occurs in is unknown to me, the module where the error occurs differs from time to time (I've seen my application.exe, WS2.dll, netcfagl3_5.dll and mscoree3_5.dll), even the error code is not always the same. (most of the time it's 0xC0000005, but i've also seen an 0X80000002 error, which is a warning accounting the first byte?)

我尝试通过 bugtrap 进行调试,但奇​​怪的是这会以相同的错误代码 (0xC0000005) 崩溃.我试图用 Visual Studio 打开 kdmp 文件,但我似乎无法理解这一点,因为它只在我进入错误时向我显示反汇编代码(除非我有正确的 .pbb 文件,我不这样做)'t).WinDbg 也是如此.

I tried debugging through bugtrap, but strangely enough this crashes with the same error code (0xC0000005). I tried to open the kdmp file with visual studio, but i can't seem to make any sense out of this because it only shows me disassembler code when i step into the error (unless i have the right .pbb files, which i don't). Same goes for WinDbg.

长话短说:坦率地说,我没有任何线索可以在哪里查找此错误,我希望 stackoverflow 上的一些聪明人可以这样做.我很高兴提供一些代码,但目前我不知道要提供哪一部分..

To make a long story short: I frankly don't have a single clue where to look for this error, and I'm hoping some bright soul on stackoverflow does. I'm happy to provide some code but at this moment I don't know which piece to provide..

非常感谢任何帮助!

正如您在我对 Hans 的评论中所见,我在取消对所有 P/Invokes 的注释后重新测试了整个程序,但这并没有解决我的问题.我尝试用尽可能少的代码重现错误,最终看起来多线程访问给我带来了所有问题.

As you can see in my comment to Hans I retested the whole program after I uncommented all P/Invokes, but that did not solve my problem. I tried reproducing the error with as little code as possible and eventually it looks like multi-threaded access is the one giving me all the problems.

在我的应用程序中,我有一个用作手指/轻弹滚动列表的用户控件.在这个控件中,我将列表中的每个项目的位图用作画布.在此画布上绘图由一个单独的线程处理,当我禁用此线程时,错误似乎消失了.. 我将对此进行更多测试并将结果发布在这里.

In my application I have a usercontrol that functions as a finger / flick scroll list. In this control I use a bitmap for each item in the list as a canvas. Drawing on this canvas is handled by a separate thread and when i disable this thread, the error seems to disappear.. I'll do some more tests on this and will post the results here.

推荐答案

原来是Interlocked引起的异常.

It turns out to be an exception caused by Interlocked.

在我的代码中,有一个整数 _drawThreadIsRunning 在绘制线程运行时设置为 1,否则设置为 0.我使用 Interlocked 设置此值:

In my code there is an integer _drawThreadIsRunning which is set to 1 when the draw-thread is running, and set to 0 otherwise. I set this value using Interlocked:

if (Interlocked.Exchange(ref _drawThreadIsRunning, 1) == 0) {/* 运行线程 */}

当我更改这条线时,整个事情都起作用了,所以似乎某处的线程安全存在问题,但我无法弄清楚.(即,我不想浪费更多时间来弄清楚)

When i change this line the whole thing works, so it seems that there is a problem with threadsafety somewhere, but i can't figure it out. (ie. i don't want to waste more time figuring it out)

感谢大家的帮助!

这篇关于无法捕获的 AccessViolationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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