Windows Services runs background.In developing time you may want to debug the service code.Some coders make this as creating a console application and running the code in it.That works of course but not a good solution....Alternatively we may use clr commands to debug a windows service itself. Here is the code block to accomplish this task....
#if (!DEBUG)
ServiceBase[] ServicesToRun;
// More than one user WindowsService_tmp may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new MailService(), new MySecondUserService()};
//
ServicesToRun = new ServiceBase[] { new Service1() };
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
Service1 service = new Service1();
service.OnStart(new string[] { ""});
// 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
No comments:
Post a Comment