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 ....