How can I restart a windows service programmatically in .NET

后端 未结 10 1250
青春惊慌失措
青春惊慌失措 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:27

    Take a look at the ServiceController class.

    To perform the operation that needs to be done when the service is restarted, I guess you should do that in the Service yourself (if it is your own service).
    If you do not have access to the source of the service, then perhaps you can use the WaitForStatus method of the ServiceController.

提交回复
热议问题