Restart a service with dependent services?

后端 未结 3 1949
广开言路
广开言路 2021-02-20 07:36

Starting with a csharp-example and duly noting related SO questions ( Restart a windows services from C# and Cannot restart a Service) and various other questions relating to

3条回答
  •  Happy的楠姐
    2021-02-20 07:46

    It sounds like you want to restart a "base" service and have all the things that rely on it get restarted as well. If so, you can't just restart all the dependant services, because they may not have been running beforehand. There's no API for this that I'm aware of.

    The way I'd do it is just write a recursive function to scan all the dependant services (and their dependancies), and add all the services which were running to a list in order.

    When you restart the base service, you can then just run through this list and start everything. Provided you haven't re-sorted the list, the services should start in the right order, and all will be well.

提交回复
热议问题