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.
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
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).
Hope this helps