How can I restart a windows service programmatically in .NET

后端 未结 10 1271
青春惊慌失措
青春惊慌失措 2020-12-02 18:21

How can I restart a windows service programmatically in .NET?
Also, I need to do an operation when the service restart is completed.

10条回答
  •  广开言路
    2020-12-02 18:49

    Call Environment.Exit with an error code greater than 0, which seems appropriate, then on install we configure the service to restart on error.

    Environment.Exit(1);
    

    I have done same thing in my Service. It is working fine.

提交回复
热议问题