我想调试窗口服务。我应该在 main() 中编写什么才能在窗口服务中启用调试。我正在使用 C# 开发窗口服务。
#if(DEBUG)
System.Diagnostics.Debugger.Break();
this.OnStart(null);
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase.Run(this);
#endif
我在上面写了代码段,但是是在线的(这个
我个人使用这种方法来调试Windows服务:
static void Main() {
if (!Environment.UserInteractive) {
// We are not in debug mode, startup as service
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new MyServer() };
ServiceBase.Run(ServicesToRun);
} else {
// We are in debug mode, startup as application
MyServer service = new MyServer();
service.StartService();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
并在您的中创建一个新方法MyServer
将使用的类OnStart
event:
public void StartService() {
this.OnStart(new string[0]);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)