问题描述
我正在通过附加到两个实例来调试具有两个正在运行的实例的Windows服务。之所以这样做,是因为我知道只有一个实例会达到我的断点,但是我想知道那是哪个实例,这样以后就不必再附加到这两个实例上。
I'm debugging a windows service which has two running instances, by attaching to both instances. I am doing this because I know only one instance will hit my breakpoint, but I'd like to know which instance that is, so that I don't have to attach to both in future.
在附加到多个进程时,是否可以确定哪个进程已达到断点?反复试验的解决方案是一次附加一个,并查看断点是否被击中,或者停止其中一个服务(通过services.msc),并查看哪个进程ID消失了-但两个解决方案似乎都无法扩展对我来说。有没有更优雅的方法?
Is there a way, when attached to multiple processes, that you can tell which one has hit a breakpoint? A trial-and-error solution would be to attach one at a time and see if the breakpoint is hit, or, stop one of the services (through services.msc) and see which process ID disappears - but neither solution seems scale-able to me. Is there a more elegant way?
谢谢!
推荐答案
您可以在以下语句中添加手表:
You could add a watch to the following statement:
System.Diagnostics.Process.GetCurrentProcess().Id
这将为您提供附加的PID(进程ID)。
您可以在Windows任务管理器中查找pid(菜单视图->选择列并勾选PID)。
This gives you the PID (process id) you are attached to.You can look for pids in windows task manager (Menu View->Select Columns and tick PID).
希望这会有所帮助
这篇关于如何判断我正在调试哪个进程(附加到多个进程)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!