2011-07-16 74 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)); 
     } 
}