WEB开发网
开发学院软件开发C语言 让你的GUI程序随WINDOWS服务一起启动 阅读

让你的GUI程序随WINDOWS服务一起启动

 2009-05-14 08:28:31 来源:WEB开发网   
核心提示: 3.2 检查并启动Windows服务///<summary>///启动已暂停或停止的服务///</summary>privatevoidStartService(){try{foreach(stringserviceNameinrwCnfg.GsServiceNam

3.2 检查并启动Windows服务

        /// <summary>
        /// 启动已暂停或停止的服务
         /// </summary>
        private void StartService()
        {

            try
            {
                foreach (string serviceName in rwCnfg.GsServiceNames)
                {
                    ServiceController myService = new ServiceController(serviceName);
                    ServiceControllerStatus status = myService.Status;
                    switch (status)
                    {
                        case ServiceControllerStatus.ContinuePending:

                            break;

                        case ServiceControllerStatus.PausePending:

                            break;
                        case ServiceControllerStatus.StartPending:

                            break;
                        case ServiceControllerStatus.Running:

                            break;
                        case ServiceControllerStatus.Paused:
                        case ServiceControllerStatus.Stopped:
                            {
                                myService.Start();
                                myService.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 2, 0));
                                Common.wLog("完成启动服务: " + myService.ServiceName + " . " + System.DateTime.Now.ToString());
                            }
                            break;
                        case ServiceControllerStatus.StopPending:

                            break;
                        default:

                            break;
                    }
                }
            }
            catch (Exception err)
            {
                Common.wLog(err.ToString());
            }
        }

上一页  1 2 3 4 5  下一页

Tags:GUI 程序 WINDOWS

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接