2013-05-31 114 views

回答

0

這個檢查你正在尋找的服務的狀態,在一個while循環,使用它的服務狀態恢復運行

string machineName = ConfigurationManager.AppSettings["ServiceMachineName"]; 
string serviceName = ConfigurationManager.AppSettings["ServiceName"]; 
ServiceController service = new ServiceController(serviceName, machineName); 
return service.Status; 

像這樣的東西開始你的應用程序:

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
//process.StartInfo.FileName = @"C:\WINDOWS\system32\iisreset.exe"; 
process.StartInfo.FileName = "cmd"; 
process.StartInfo.Arguments = "/C iisreset /STOP"; 
process.StartInfo.UseShellExecute = false; 
process.StartInfo.CreateNoWindow = true; 
process.StartInfo.RedirectStandardError = true; 
process.StartInfo.RedirectStandardOutput = true; 
process.Start(); 
process.WaitForExit(); 

這樣,當應用程序退出循環繼續尋求過程...

相關問題