无法捕获的AccesViolationException [英] Uncatchable AccesViolationException

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

问题描述

我快要绝望了.我正在使用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文件,而我没有) ').对于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..

任何帮助将不胜感激!

[2010年5月3日编辑]

正如您在对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.

推荐答案

事实证明这是由互锁引起的异常.

It turns out to be an exception caused by Interlocked.

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

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) { /* run thread */ }

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

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)

感谢帮助人员!

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

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