1. Create a new Windows Service Project using the default template.
2. Open "Program.cs"
3. In "Main()" use the following code...
Code Snippet
- #if (!DEBUG)
- System.ServiceProcess.ServiceBase[] ServicesToRun;
- System.ServiceProcess.ServiceBase.Run(ServicesToRun);
- #else
- // Debug code: this allows the process to run as a non-service.
- // It will kick off the service start point, but never kill it.
- // Shut down the debugger to exit
- service.[Service Main Method]();
- // Put a breakpoint on the following line to always catch
- // your service when it has finished its work
- System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
- #endif
End of Code Snippet
4. Replace [Service Name] with the class name of your service.
5. Add a method to your [Service Name].cs file (which is also called from "OnStart(string[] args)". This method will contain all of the logic which is debugged. Reference this method in "Program.cs"
6. Set the compiler to DEBUG mode, and start putting some breakpoints in!!
The same applies for VB.NET users
No comments:
Post a Comment