禁止从无人值守代码启动的.NET应用程序的异常弹出窗口 [英] Suppress exception popup window for .NET application launched from unattended code

查看:257
本文介绍了禁止从无人值守代码启动的.NET应用程序的异常弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预建的.NET控制台应用程序EXE,我使用Process类从单独的C#代码启动。如果应用程序抛出一个未处理的异常,会弹出一个窗口(遇到问题并需要关闭...,并显示Debug,发送错误报告和不发送按钮) 。



如果发生这种情况,控制不会返回到我的代码,直到我按不要发送按钮按钮,这对我来说不方便,因为我想要它能够运行无人值守。



有没有办法我可以在不改变预先构建的应用程序的情况下抑制这个弹出窗口,或者至少在一段时间后结束进程过去。在任何解决方案中,我仍然希望在控制台输出中捕获异常,所以我可以从我的代码中读取异常 - 只要我手动按不要发送按钮,这实际上可以正常工作,所以我只想要发生没有用户交互。



谢谢...

解决方案

我最终的解决方案是为外部过程定义最大时间,在此之后,强制它到达并结束,并且还会杀死DW20的任何实例,这是错误报告窗口运行的过程。 p>

  int waitTimeSecs = 120; 

bool cleanExit = process.WaitForExit(waitTimeSecs * 1000);
if(!process.HasExited)
{
process.CloseMainWindow();
System.Threading.Thread.Sleep(2000);
}

if(!process.HasExited)
{
process.Kill();
process.WaitForExit();
//如果异常窗口已弹出,则需要被杀死
// DW20是Dr. Watson应用程序错误处理过程
foreach(Process.GetProcessesByName( DW20))
{
process.CloseMainWindow();
System.Threading.Thread.Sleep(2000);
if(!process.HasExited)
process.Kill();
}
}

我唯一的缺点是关闭其他错误报告那个窗口可能会在那个时候开放,但对我而言,现在已经足够好了。


I have a pre-built .NET Console application EXE that I am launching from separate C# code using the Process class. If the application throws an unhandled exception, a window pops up (the one that says " has encountered a problem and needs to close..." and has "Debug", "Send Error Report" and "Don't Send" buttons).

If this happens, control does not return to my code until I press the "Don't send" button button, which is inconvenient for me as I want it to be able to run unattended.

Is there anyway I can suppress this pop-up somehow without changing the pre-built application, or at least end the process after a certain time has elapsed. Ideally in any solution I still want the exception to be captured in the console output so I can read it from my code - this actually does work fine as long as I manually press the "Don't Send" button, so I just want this to happen without user interaction.

Thanks...

解决方案

The solution I ended up with was to defined a maximum time for the external process and after this time, force it to come to and end AND also kill any instances of DW20, which is the process that the error reporting window runs under.

int waitTimeSecs = 120;    

bool cleanExit = process.WaitForExit(waitTimeSecs * 1000);
if (!process.HasExited)
{
    process.CloseMainWindow();
    System.Threading.Thread.Sleep(2000);
}

if (!process.HasExited)
{
    process.Kill();
    process.WaitForExit();
    // if an exception window has popped up, that needs to be killed too
    // DW20 is the Dr. Watson application error handling process
    foreach (var process in Process.GetProcessesByName("DW20"))
    {
        process.CloseMainWindow();
        System.Threading.Thread.Sleep(2000);
        if (!process.HasExited)
            process.Kill();
    }
}

The only drawback I can see is closing other error reporting windows that might happen to open at that time, but for me this is good enough right now.

这篇关于禁止从无人值守代码启动的.NET应用程序的异常弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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