如何:调试 Windows 服务应用程序How to: Debug Windows Service Applications

必须从服务控制管理器的上下文中而不是 Visual Studio 中运行服务。A service must be run from within the context of the Services Control Manager rather than from within Visual Studio. 因此,调试服务不像调试其他 Visual Studio 应用程序类型一样简单。For this reason, debugging a service is not as straightforward as debugging other Visual Studio application types. 要调试服务,必须启动该服务,然后将调试器附加到该服务正在其中运行的进程中。To debug a service, you must start the service and then attach a debugger to the process in which it is running. 然后你可以使用所有 Visual Studio 的标准调试功能来调试你的应用程序。You can then debug your application by using all of the standard debugging functionality of Visual Studio.