Friday, September 01, 2006

Debugging Windows Services In Visual Studio 2005

To do that, change the body of the Main method of the Windows service:


#if (!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new MyService() };
ServiceBase.Run(ServicesToRun);
#else
MyService service = new MyService();
service.MyOnStart();
#endif

You will get two error messages at the beginning but you can continue debugging.

No comments: