无法调试使用Process.Start()开始的项目 [英] Can not debug a Project started using Process.Start()
问题描述
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屋!