Troubleshooting: Debugging Windows Services

Note

This article doesn't apply to hosted services in .NET. For the latest content on Windows services using Microsoft.Extensions.Hosting.BackgroundService and the Worker Service template, see:

When you debug a Windows service application, your service and the Windows Service Manager interact. The Service Manager starts your service by calling the OnStart method, and then waits 30 seconds for the OnStart method to return. If the method does not return in this time, the manager shows an error that the service cannot be started.

When you debug the OnStart method as described in How to: Debug Windows Service Applications, you must be aware of this 30-second period. If you place a breakpoint in the OnStart method and do not step through it in 30 seconds, the manager will not start the service.

See also