What is the proper way for a Windows service to fail?

前端 未结 5 1695
日久生厌
日久生厌 2020-12-05 02:17

I have inherited a Windows service written in C#. Under rare conditions it fails badly. However, it isn\'t at all clear how to fail well. Ross Bennett states the problem e

5条回答
  •  自闭症患者
    2020-12-05 02:30

    After some testing I found the following works in cases where you calling Stop might cause other issues:

            ExitCode = 1;
            Environment.Exit(1);
    

    Just calling Environment.Exit doesn't make the SCM do fault handling, but first setting the ServiceBase ExitCode does.

提交回复
热议问题