【发布时间】:2015-08-26 17:26:30
【问题描述】:
这个话题已经在很多问题中被问及并得到了回答,我做了尽职调查,但我就是不知道为什么我会遇到这个问题。
在 testfailure.exe 中:
namespace testfailture
{
class Program
{
static void Main(string[] args)
{
try
{
throw new Exception("I want to report this in the parent window");
}
catch (Exception ex)
{
throw ex;
}
}
}
在 test.exe 中:
internal void Execute(string packageVersion)
{
Process exeProcess = new Process();
exeProcess.StartInfo.FileName = "testfailure.exe";
exeProcess.StartInfo.RedirectStandardOutput = true;
exeProcess.StartInfo.UseShellExecute = false;
exeProcess.StartInfo.CreateNoWindow = true;
try
{
exeProcess.Start();
Console.WriteLine(exeProcess.StandardOutput.ReadToEnd());
}
catch (Exception ex)
{
throw ex;
}
}
当我运行程序时,我得到了弹出窗口,并且在采取行动之前不会让程序继续运行。
我认为这是由于 JIT 调试造成的,所以我做了以下所有操作: https://social.msdn.microsoft.com/Forums/vstudio/en-US/a52eb0ae-bcd8-4043-9661-d5fc3aa5167c/getting-rid-of-justintime-debugger?forum=vsdebug
这是我遇到的一个问题,但最终我想做的是子进程将错误(不是 console.writeline,因为我想用它来报告状态)报告给父进程并显示在父进程的窗口中。
有什么想法吗?
顺便说一句,我正在使用 Visual Studio Professional 2012。非常感谢您的帮助。
谢谢!
编辑#1----------------------------
我的流程完全期望一切正常,但我想做的是为意外失败编写代码。当失败时,我希望有一个良好的对话,以便我可以轻松快速地检测和调试。
【问题讨论】:
-
不要射击信使,而是修复您的代码。异常不能跨越进程边界,你的程序应该像这样崩溃。你需要重新考虑你的策略,这是行不通的。
-
是的,我同意。我的流程完全期望一切正常,但我正在为意外失败进行编码。发生这种情况时,我正在做的事情将帮助我快速检测和调试。
-
另外,除非你想重置异常的调用栈,否则不要
throw ex;。
标签: c# visual-studio-2012 visual-studio-debugging jit process.start