Stop and Start IIS programatically. Quickly and safe way

My situation: when I deploy assemblies .NET in GAC, I get errors (Cannot access to xxx.dll because is in use for another process). The IIS use those dll (assemblies).

Which is the best way (more performance,quick and safe way) or all ways to stop, start IIS 6.0 Windows 2003 ? (for C#, .NET 3.5)

options, I think:

  1. Detect IIS installed in machine.

  2. Process.Start() using commands: iisreset /stop andiisreset /start

  3. Use ServiceController class for get "World Wide Web Publishing Service" ( "W3SVC" ) and do stop

    controller.Stop();
    controller.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(timeoutSeconds));
    

    and do start

    controller.Start();
    controller.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(timeoutSeconds));
    
  4. Process.Start() using command: taskkill /IM aspnet_wp.exe /F (use w3wp.exe in Win2003)

  5. another options that I don't know?

6
задан abatishchev 10 February 2011 в 15:20
поделиться