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?
Thanks!
To change the startup project, in Solution Explorer, right-click a different project and select Set as StartUp Project. To start debugging a project from Solution Explorer without making it the startup project, right-click the project and select Debug > Start new instance or Step into new instance.
To debug multiple services at the same timeOpen the folder corresponding to your first service in VS Code. In VS Code, select File > Add Folder to Workspace…, and pick the folder corresponding to your other service.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With