当前位置: 首页>>代码示例>>C#>>正文


C# ServiceControllerStatus.ToString方法代码示例

本文整理汇总了C#中ServiceControllerStatus.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceControllerStatus.ToString方法的具体用法?C# ServiceControllerStatus.ToString怎么用?C# ServiceControllerStatus.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceControllerStatus的用法示例。


在下文中一共展示了ServiceControllerStatus.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunServer

        /// <summary>
        /// Change the service status
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="newStatus"></param>
        public static void RunServer(ServiceController sc, ServiceControllerStatus newStatus)
        {
            try
              {
            if (sc.Status == newStatus)
              return;

            // TODO: Need better waiting mechanism (ideally show a progress bar here...)
            // for now wait 30 seconds and confirm the new status afterward.
            var waitAmount = new TimeSpan(0, 0, 30);

            switch (newStatus)
            {
              case ServiceControllerStatus.Running:
            //Status("Starting server, please wait...");
            sc.Start();
            sc.WaitForStatus(newStatus, waitAmount);
            break;

              case ServiceControllerStatus.Stopped:
            //Status("Stopping server, please wait...");
            sc.Stop();
            sc.WaitForStatus(newStatus, waitAmount);
            break;

              default:
            throw new Exception("Unsupported action = " + newStatus.ToString());
            }

            if (sc.Status != newStatus)
              throw new ApplicationException("Service is not " + newStatus);

              }
              catch (Exception ex)
              {
            Debug.WriteLine(ex.Message);
            throw;
              }
        }
开发者ID:dbremner,项目名称:hycs,代码行数:44,代码来源:serviceUtil.cs

示例2: HandleServiceState

 private void HandleServiceState(ServiceControllerStatus _status)
 {
     switch (_status)
     {
         case ServiceControllerStatus.Stopped:
             btnStartStopService.Content = "Start";
             lblServiceState.Content = "Service Stopped";
             lblServiceState.Foreground = System.Windows.Media.Brushes.Red;
             break;
         case ServiceControllerStatus.Running:
             btnStartStopService.Content = "Stop";
             lblServiceState.Content = "Service Started";
             lblServiceState.Foreground = System.Windows.Media.Brushes.Green;
             break;
         case ServiceControllerStatus.StartPending:
             btnStartStopService.Content = "Stop";
             lblServiceState.Content = "Service Starting";
             lblServiceState.Foreground = System.Windows.Media.Brushes.Teal;
             break;
         default:
             lblServiceState.Foreground = System.Windows.Media.Brushes.Teal;
             lblServiceState.Content = "Service " + _status.ToString();
             break;
     }
 }
开发者ID:Thorsten1982,项目名称:MPExtended,代码行数:25,代码来源:MediaAccessServer.xaml.cs

示例3: UpdateServiceUI

        private void UpdateServiceUI()
        {
            if (mediaServer != null && standAloneMode == true)
            {
                serverStatus1.Text = "Serving " + mediaServer.TotalFileCount + " Files in " + mediaServer.TotalDirectoryCount + " Directories";
                serverStatus2.Text = "";
                UpdateDirectoriesUI();
                return;
            }

            if (serviceController == null)
            {
                try
                {
                    serviceController = new ServiceController("AV Media Server");
                    serviceStatus = serviceController.Status;
                }
                catch (System.InvalidOperationException)
                {
                    serverStatus1.Text = "Media Server Service Not Installed";
                    serverStatus2.Text = "Use \"Standalone Mode\" for autonomous operation";
                    serviceController = null;
                    serviceStatus = ServiceControllerStatus.Stopped;
                    return;
                }
            }

            ServiceController serviceController2 = new ServiceController("AV Media Server");
            serviceStatus = serviceController2.Status;
            switch (serviceStatus)
            {
                case ServiceControllerStatus.Running:
                    if (mediaServer == null)
                    {
                        serverStatus1.Text = "Connecting...";
                        serverStatus2.Text = "";
                        Connect();
                    }
                    else
                    {
                        serverStatus1.Text = "Media Server Serving "+mediaServer.TotalFileCount+" Files in "+mediaServer.TotalDirectoryCount+" Directories";
                        serverStatus2.Text = "";
                    }
                    break;
                case ServiceControllerStatus.Stopped:
                    serverStatus1.Text = "Media Server Service is Stopped";
                    serverStatus2.Text = "";
                    break;
                default:
                    serverStatus1.Text = "Media Server Service is " + serviceStatus.ToString();
                    serverStatus2.Text = "";
                    break;
            }
            serviceController2.Close();
            serviceController2.Dispose();
            serviceController2 = null;
            UpdateDirectoriesUI();
        }
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:58,代码来源:MainForm.cs

示例4: GetDisplayName

            public string GetDisplayName(ServiceControllerStatus scs)
            {
                //Stopped
                string name = "已停止";

                if (scs.ToString().Equals("Running"))
                {
                    name = "已运行";
                }

                return name;
            }
开发者ID:3gbywork,项目名称:WindowsServicesManager,代码行数:12,代码来源:MainWindow.xaml.cs

示例5: setServiceStatus

        private void setServiceStatus(ServiceControllerStatus status)
        {
            if (serviceController.Status.Equals(status)) //already in the wanted status
            {
                OnProgress(processIdx + 1);
            }
            else
            {
                try
                {
                    TimeSpan timeoutSec = TimeSpan.FromSeconds(timeout);

                    bool tryAgain = false;
                    int tryCount = 0;

                    do
                    {
                        try
                        {
                            if (status.Equals(ServiceControllerStatus.Running))
                                serviceController.Start(); //TODO: support arguments
                            else
                                serviceController.Stop();
                        }
                        catch (InvalidOperationException e)
                        {
                            //in some cases, the service status might be changed although the exception is thrown
                            Thread.Sleep(TimeSpan.FromSeconds(5)); //wait a little bit time to try again

                            serviceController.Refresh();
                            if (serviceController.Status.Equals(status)) //equal
                                tryAgain = false;
                            else if (tryCount < TOTAL_TRY) //not equal, not reach total
                                tryAgain = true;
                            else //when not equal to status, AND reach total try
                                throw e;

                            tryCount++;
                        }
                    } while (tryAgain);

                    serviceController.WaitForStatus(status, timeoutSec);

                    Console.WriteLine(serviceController.Status.ToString());

                    //check the status to make sure it is started properly
                    if (serviceController.Status.Equals(status))
                    {
                        OnProgress(processIdx + 1);
                    }
                    else
                    {
                        throw new InvalidOperationException(serviceController.ServiceName + " cannot be changed to status " + status.ToString());
                    }
                }
                //TODO: there should be configuration for the app
                //when error occurs to a service, should it stop or continue to next service?
                catch (InvalidOperationException e)
                {
                    OnError(e);
                }
                catch (System.ServiceProcess.TimeoutException e)
                {
                    OnError(e);
                }
            }
        }
开发者ID:rocksoccer,项目名称:AppStarter,代码行数:67,代码来源:ServiceUtil.cs


注:本文中的ServiceControllerStatus.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。