I know it's late, but we also handle Windows service debugging
First create a class that will act as a service.
Add appropriate methods to start, stop, pause, etc.
Add a window form to a service project.
In the service code, create the service class created above and make the calls necessary to start and stop the service in the ServiceBase class
Open Program.cs and add the following
#if DEBUG [STAThread] #endif static void Main() { try { #if DEBUG Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new DebugForm()); #else ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new YourWindowsService() }; ServiceBase.Run(ServicesToRun); #endif } catch (Exception e) { logger.Error(DateTime.Now.ToString() + " - " + e.Source + " - " + e.ToString() + "\r\n------------------------------------\r\n"); } }
When launched in DEBUG mode, a window form will start. Just remember to build in Release mode when you're done. Of course, the compilation conditional variable can be anything you like. You can even create separate projects, so the debug form is your own project.
Hope this helps
Coach David Apr 6 '13 at 1:08 2013-04-06 01:08
source share