Hello
Thank you for posting in Q&A forum.
To debug a service
- Build your service in the Debug configuration.
- Install your service. For more information, see How to: Install and Uninstall Services.
- Start your service, either from Services Control Manager, Server Explorer, or from code. For more information, see How to: Start Services.
- Start Visual Studio with administrative credentials so you can attach to system processes.
- (Optional) On the Visual Studio menu bar, choose Tools, Options. In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box, and then choose the OK button.
- On the menu bar, choose Attach to Process from the Debug or Tools menu. (Keyboard: Ctrl+Alt+P)
The Processes dialog box appears.
- Select the Show processes from all users check box.
- In the Available Processes section, choose the process for your service, and then choose Attach.
Tip
The process will have the same name as the executable file for your service.
The Attach to Process dialog box appears.
Choose the appropriate options and then choose OK to close the dialog box.
Note
You are now in debug mode.
- Set any breakpoints you want to use in your code.
- Access the Services Control Manager and manipulate your service, sending stop, pause, and continue commands to hit your breakpoints. For more information about running the Services Control Manager, see How to: Start Services. Also, see Troubleshooting: Debugging Windows Services.
Reference:
How to: Debug Windows Service Applications - .NET Framework | Microsoft Learn
I hope the information above is helpful.
If you have any questions or concerns, please feel free to let us know.
Best Regards,
Daisy Zhou
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.