【问题标题】:Disable JIT debugging禁用 JIT 调试
【发布时间】: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


【解决方案1】:

抛出未处理的异常不能传递给父进程。

然而,你可以做的是将数据写入 StandardError,并在父进程中捕获它。

下面的例子来自MSDN

    Public Sub Main()
      Dim args() As String = Environment.GetCommandLineArgs()
      Dim errorOutput As String = "" 
      ' Make sure that there is at least one command line argument. 
      If args.Length <= 1 Then
         errorOutput += "You must include a filename on the command line." +
                        vbCrLf
      End If 

      For ctr As Integer = 1 To args.GetUpperBound(0)
         ' Check whether the file exists. 
         If Not File.Exists(args(ctr)) Then
            errorOutput += String.Format("'{0}' does not exist.{1}",
                                         args(ctr), vbCrLf)
         Else 
            ' Display the contents of the file. 
            Dim sr As New StreamReader(args(ctr))
            Dim contents As String = sr.ReadToEnd()
            sr.Close()
            Console.WriteLine("***** Contents of file '{0}':{1}{1}",
                              args(ctr), vbCrLf)
            Console.WriteLine(contents)
            Console.WriteLine("*****{0}", vbCrLf)
         End If 
      Next 

      ' Check for error conditions. 
      If Not String.IsNullOrEmpty(errorOutput) Then 
         ' Write error information to a file.
         Console.SetError(New StreamWriter(".\ViewTextFile.Err.txt"))
         Console.Error.WriteLine(errorOutput)
         Console.Error.Close()
         ' Reacquire the standard error stream. 
         Dim standardError As New StreamWriter(Console.OpenStandardError())
         standardError.AutoFlush = True
         Console.SetError(standardError)
         Console.Error.WriteLine("{0}Error information written to ViewTextFile.Err.txt",
                                 vbCrLf)
      End If 
   End Sub 

【讨论】:

  • 这正是我想要的!我应该在控制台上进行更多研究。谢谢!
猜你喜欢
  • 1970-01-01
  • 2023-04-11
  • 2019-07-23
  • 1970-01-01
  • 1970-01-01
  • 2023-02-13
  • 2019-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多