【发布时间】:2019-05-13 03:04:18
【问题描述】:
在我运行程序大约一天后,我遇到了一个问题,即 AccessViolationException 未处理。
(更多信息:我使用的是 Visual Studio 2010)
但是,它没有说明此异常发生的位置,给了我两个选项,即“确定”和“继续”。当我按下确定时,什么也没发生,所以我按下继续,程序停止调试。
当我试图找到解决方案时,我明白我可以实施HandleProcessCorruptedStateExceptions 来解决这个问题。但是,我不知道从哪里开始。
我是否只包含以下代码?我在哪里包含这些代码?
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
public static int Main()
{
try
{
// Catch any exceptions leaking out of the program CallMainProgramLoop();
}
catch (Exception e)
// We could be catching anything here
{
// The exception we caught could have been a program error
// or something much more serious. Regardless, we know that
// something is not right. We'll just output the exception
// and exit with an error. We won't try to do any work when
// the program or process is in an unknown state!
System.Console.WriteLine(e.Message);
return 1;
}
return 0;
}
或者,我也可以这样做legacyCorruptedStateExceptionsPolicy,但它说我应该在配置文件中输入所需的语句。我在哪里可以找到配置文件?
感谢所有回复!
【问题讨论】:
-
你说“我运行我的程序大约一天”然后“我按下继续并且程序停止调试” - 是吗意思是你在 Visual Studio 调试器中运行你的程序好几天?
-
@vasily.sib 是的,我目前正在为一家公司做一个项目,它需要运行几天的程序。但是这个异常导致它停止,所以我被告知要修复它。我正在使用 Visual Studio 2010。
-
看看this question。此外,请注意,Visual Studio 2010 已于 2015 年结束生命周期(并将在明年达到延长支持的结束日期)。
-
@vasily.sib 非常感谢您的帮助。我知道我必须实现另一篇文章中所述的代码,但我只是创建函数而已吗?我必须在我的代码中的某个地方调用它吗?我很抱歉提出多余的问题,因为程序再次运行,所以我无法修改代码。我只是想先澄清一下,一旦异常再次出现,我可以立即更改它。
标签: c# visual-studio error-handling