无法调试使用Process.Start()开始的项目 [英] Can not debug a Project started using Process.Start()

查看:131
本文介绍了无法调试使用Process.Start()开始的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个C#WinForm项目在同一个解决方案中可以调用它们A和B.项目A通过下面的调用启动进程B.

  ProcessStartInfo psi = new ProcessStartInfo(); 
psi.FileName = Task.EXEFilename;
psi.WorkingDirectory = Path.GetDirectoryName(Data.EXEFilename);
Process.Start(psi);

进程B正确启动。我正在调试过程B时调试过程B.我认为在B中设置一个断点就足够了,但是它永远不会被打。我已经验证了启动的进程是在B的bin / debug文件夹中。我不应该在这种情况下附加到进程以将调试从A切换到B?

解决方案

在第二个项目中,它检查其命令行参数,如果它看到类似于 - debug 被传入第一个参数第二个程序启动调试器本身

  private static void Main(string [] args)
{
//如果没有附加调试器,并且参数--debug被传递启动调试器
if(args.Length == 1&& args [0] ==--debug& & Debugger.IsAttached == false)
Debugger.Launch();

//(snip)你的程序的其余部分

}

当您执行此操作时,您将看到一个对话框窗口,您可以选择打开Visual Studio的新副本或仅使用已打开的副本。








您还可以将子进程放在图像文件执行选项注册表项


I have two C# WinForm projects in the same solution lets call them A and B. Project A starts Process B via a call like below

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Task.EXEFilename;
psi.WorkingDirectory = Path.GetDirectoryName(Data.EXEFilename);
Process.Start(psi);

The process B is started correctly. I wanted to debug the process B while I am debugging A. I thought putting a break point in the B would be enough but it is never hit. I have verified that process that is started is in the bin/debug folder of the B. I should not be doing attached to process in this case to switch debugging from A to B ?

解决方案

In the 2nd project have it check its command line arguments, if it sees something like --debug was passed in as the first argument the 2nd program launches the debugger itself

private static void Main(string[] args)
{
    //If no debugger is attached and the argument --debug was passed launch the debugger
    if (args.Length == 1 && args[0] == "--debug" && Debugger.IsAttached == false)
        Debugger.Launch();

    //(snip) the rest of your program

}

When you do this you will get a dialog window that will allow you to choose to open a new copy of Visual Studio or just use your already open copy.


You can also put the child process in the Image File Execution Options registry key.

这篇关于无法调试使用Process.Start()开始的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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