C # restart system services

Source: Internet
Author: User

Some time ago, the local development team wanted to use the group's unified authentication component.ProgramHowever, the running results were not very good. Later I checked the reason for a long time and found that the memory of a component written by the group company had been very high and accessed once, and the memory was not accumulated, but it is not released, which will eventually result in system memory consumption ..... this component cannot be modified locally. The only way is to restart the Service regularly on a daily basis ....

C # restart the service, including IIS, etc,CodeSimple. Just copy a paragraph.

Stop
Servicecontroller SC = new servicecontroller ("IISADMIN ");
If (SC. Status = servicecontrollerstatus. Running)
SC. Stop ();

Dynamic IIS server
Servicecontroller SC = new servicecontroller ("IISADMIN ");
SC. Start ();

Duplicate
Using system. diagnostics;
Process. Start ("iisreset ");

The above code can probably meet the requirements for restart, but it is best to add a wait state function and a refresh function ....

Problem description:
If the above Code is written as a winform program, it is okay to start any program. However, writing it as a Windows service still requires some operations...

First, you need to determine whether the selected localserver, LocalSystem, etc. are selected when the service is released ....

Then, determine the method in which the service to be started is released. localserver, LocalSystem, and so on... (Service-> service to be restarted-> properties-> login)

Then, the access permission of the service component to be restarted is given ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.