且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

本地计算机上的Windows服务启动,然后停止了错误

更新时间:2022-04-12 22:46:58

如果服务那样启动和停止,则意味着您的代码将引发未处理的异常。这很难调试,但是有一些选择。

If the service starts and stops like that, it means your code is throwing an unhandled exception. This is pretty difficult to debug, but there are a few options.


  1. 咨询Windows Event Viewer 。通常,您可以转到计算机/服务器管理器,然后单击事件查看器-> Windows日志-> 应用程序来完成此操作。您可以在此处查看引发异常的原因,这可能有所帮助,但您没有获得堆栈跟踪。

  2. 将程序逻辑提取到库类项目中。现在,创建程序的两个不同版本:控制台应用程序(用于调试)和Windows服务。 (这是一些初期工作,但是从长远来看可以节省很多焦虑。)

  3. 添加更多try / catch块并登录到应用程序以更好地了解内容

  1. Consult the Windows Event Viewer. Normally you can get to this by going to the computer/server manager, then clicking Event Viewer -> Windows Logs -> Application. You can see what threw the exception here, which may help, but you don't get the stack trace.
  2. Extract your program logic into a library class project. Now create two different versions of the program: a console app (for debugging), and the windows service. (This is a bit of initial effort, but saves a lot of angst in the long run.)
  3. Add more try/catch blocks and logging to the app to get a better picture of what's going on.