如何在没有附加进程的情况下调试Window服务方法。
答案 0 :(得分:0)
#if (!DEBUG)
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new BirthdayService()
};
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
BirthdayService service = new BirthdayService();
service.InitializeUsersTable();
service.GetUserAndSendMail();
// 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