2011-07-16 54 views

回答

2

您可以在Windows的每個服務的相關設置。

您可以進入控制面板 - >管理工具 - >服務(或從命令行運行'services.msc')。通過雙擊任何服務並轉到依賴關係選項卡,您可以看到每個服務依賴的內容。

你的服務依賴於MySql服務,所以MySql應該在它的依賴關係列表中。

您可以將項目添加到依賴關係,這裏是如何做到這一點的描述:

https://serverfault.com/questions/24821/how-to-add-dependency-on-a-windows-service-after-the-service-is-installed

1
+0

+1不錯的鏈接文章,直接去泳池室 –

+0

我會參考這個鏈接它的作品,但是當我將重新啓動計算機2次然後它的作品和一個空白的消息框顯示在電腦中味精框兩個按鈕顯示是或否,如果pres是的,它會重新啓動計算機&按否,它不會做任何事情,爲什麼這個按鈕顯示電腦 – user847455

1

,如果你想自己不依賴做到這一點試試下面的代碼

//Check if service is running 
ServiceController mysqlServiceController = new ServiceController(); 
mysqlServiceController.ServiceName = "MySql"; 
var timeout = 3000; 

//Check if the service is started 
if (mysqlServiceController.Status == System.ServiceProcess.ServiceControllerStatus.Stopped 
       || mysqlServiceController.Status == System.ServiceProcess.ServiceControllerStatus.Paused) 
{ 
     mysqlServiceController.Start(); 

     try 
     { 
      //Wait till the service runs mysql 
      ServiceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, timeout, 0)); 
     } 
     catch (System.ServiceProcess.TimeoutException) 
     { 
      //MessageBox.Show(string.Format("Starting the service \"{0}\" has reached to a timeout of ({1}) minutes, please check the service.", mysqlServiceController.ServiceName, timeout)); 
     } 
}