首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >禁用JIT调试

禁用JIT调试
EN

Stack Overflow用户
提问于 2015-08-26 17:26:30
回答 1查看 729关注 0票数 1

这个话题在很多问题中都得到了询问和回答,我尽了应有的努力,但我只是不明白为什么我会有这样的问题。

In testfailure.exe:

代码语言:javascript
运行
复制
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;
      }
   }
}

In test.exe:

代码语言:javascript
运行
复制
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,因为我希望将其用于报告状态)。

有什么想法吗?

顺便说一下,我正在使用2012。非常感谢你的帮助。

谢谢!

编辑#1

我的流程完全期望一切都能正常工作,但我要做的是为意外的失败编写代码。当失败时,我希望有一个好的对话,这样我就可以很容易和迅速地检测和调试。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-26 17:43:36

不能将引发未处理的异常传递给父进程。

但是,您可以做的是将数据写入StandardError,并在父进程中捕获该数据。

下面的示例来自MSDN

代码语言:javascript
运行
复制
    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 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32232961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档