我杀死进程时为什么会收到AccessViolationException?

时间:2012-08-08 18:41:38

标签: c# winforms

我正在使用一个用C#编写的.EXE程序(从一家公司购买) 有时我需要关闭它(从外部,而不是手动 - 我使用我的小型C#程序,在需要时代替Process.Kill) 如果程序没有做任何事情 - 我可以轻易杀死它 但是,如果它正在做一些“工作”(我认为它的代码中是“计时器”或“后台工作者”) - 它会关闭,但会给出一个小的弹出窗口,说“致命错误”(和“确定”按钮)。我点击“确定”然后它会给出一个更大的弹出窗口说:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at
System.Windows.Forms.UnsafeNetiveMethods.DispatchMessageA(MSG&msg)
at 
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UNsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(in t32 dbComponentID, Int32 Reason, Int32 pv LoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason ApplicationContext context)
at
System.Windows.Forms.Applicaion.ThreadContext.RunMessageLoop(Int32reason, ApplicationContext context_
at System.Windows.Forms.Application.Run(Form mainForm)
at cawf.xad70bf2c5a1a269d.xef498c90a0302180()

(CAWF是我刚刚杀死他们的进程的名称)。
在我点击Ok之后 - 我必须再次杀死它,然后才会死掉 他们的支持称这是Windows错误所以他们无能为力 我的猜测是,他们的背景工作者不想在某事物中间被打断时死去。

有没有办法杀死它“好方法”(这样它不会给出这些错误)?

2 个答案:

答案 0 :(得分:2)

是的,将WM_CLOSE发布到其主窗口并让它正常关闭。有关详细信息,请参阅此答案:How to use WM_Close in C#?

答案 1 :(得分:0)

如果你想杀死它,那么通过运行命令

杀死它
win key + R

然后输入

tskill cawf

tskill cawf.exe

尝试其中一个。