禁用 JIT 调试
Disable JIT debugging
此主题已在许多问题中被询问和回答,我做了尽职调查,但我就是不明白为什么我会遇到这个问题。
在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 因为我想用它来报告状态)并显示在父级的 window.
有什么想法吗?
顺便说一下,我使用的是 Visual Studio Professional 2012。非常感谢您的帮助。
谢谢!
编辑 #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
此主题已在许多问题中被询问和回答,我做了尽职调查,但我就是不明白为什么我会遇到这个问题。
在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 因为我想用它来报告状态)并显示在父级的 window.
有什么想法吗?
顺便说一下,我使用的是 Visual Studio Professional 2012。非常感谢您的帮助。
谢谢!
编辑 #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