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


C# ServiceControllerStatus类代码示例

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


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

示例1: GetServiceList

        /// <summary>
        /// 获取服务列表
        /// </summary>
        /// <returns></returns>
        public static IList<ServiceInformation> GetServiceList(string contains, ServiceControllerStatus status)
        {
            IList<ServiceInformation> servicelist = new List<ServiceInformation>();
            ServiceController[] services = ServiceController.GetServices();
            foreach (ServiceController s in services)
            {
                if (s.Status != status) continue;
                if (string.IsNullOrEmpty(contains))
                {
                    servicelist.Add(new ServiceInformation(s.ServiceName));
                }
                else
                {
                    if (s.ServiceName != null && s.ServiceName.ToLower().Contains(contains.ToLower()))
                    {
                        servicelist.Add(new ServiceInformation(s.ServiceName));
                    }
                    else if (s.DisplayName != null && s.DisplayName.ToLower().Contains(contains.ToLower()))
                    {
                        servicelist.Add(new ServiceInformation(s.ServiceName));
                    }
                }
            }

            return servicelist;
        }
开发者ID:rajayaseelan,项目名称:mysoftsolution,代码行数:30,代码来源:InstallerUtils.cs

示例2: ChangeServiceStatus

        /// <summary>
        /// Checks the status of the given controller, and if it isn't the requested state,
        /// performs the given action, and checks the state again.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="status"></param>
        /// <param name="changeStatus"></param>
        public static void ChangeServiceStatus(ServiceController controller, ServiceControllerStatus status, Action changeStatus)
        {
            if (controller.Status == status)
            {
                Console.Out.WriteLine(controller.ServiceName + " status is good: " + Enum.GetName(typeof(ServiceControllerStatus), status));
                return;
            }

               Console.Out.WriteLine((controller.ServiceName + " status is NOT " + Enum.GetName(typeof(ServiceControllerStatus), status) + ". Changing status..."));

            try
            {
                changeStatus();
            }
            catch (Win32Exception exception)
            {
                ThrowUnableToChangeStatus(controller.ServiceName, status, exception);
            }
            catch (InvalidOperationException exception)
            {
                ThrowUnableToChangeStatus(controller.ServiceName, status, exception);
            }

            var timeout = TimeSpan.FromSeconds(3);
            controller.WaitForStatus(status, timeout);
            if (controller.Status == status)
                Console.Out.WriteLine((controller.ServiceName + " status changed successfully."));
            else
                ThrowUnableToChangeStatus(controller.ServiceName, status);
        }
开发者ID:petarvucetin,项目名称:NServiceBus,代码行数:37,代码来源:ProcessUtil.cs

示例3: ControlService

        bool ControlService(ServiceControllerStatus status, Action<ServiceController> controlAction)
        {
            if (controller.Status == status)
            {
                log.Debug("The {0} service is already in the requested state: {1}", controller.ServiceName, status);
                return false;
            }

            log.Debug("Setting the {0} service to {1}", controller.ServiceName, status);

            try
            {
                controlAction(controller);
            }
            catch (Exception ex)
            {
                string message = string.Format("The {0} service could not be set to {1}", controller.ServiceName, status);
                throw new InvalidOperationException(message, ex);
            }

            controller.WaitForStatus(status, timeout);
            if (controller.Status == status)
            {
                log.Debug("The {0} service was set to {1} successfully", controller.ServiceName, status);
            }
            else
            {
                string message = string.Format("A timeout occurred waiting for the {0} service to be {1}",
                                               controller.ServiceName,
                                               status);
                throw new InvalidOperationException(message);
            }

            return true;
        }
开发者ID:alexmg,项目名称:Rebus,代码行数:35,代码来源:WindowsService.cs

示例4: InitializeTrayIconAndProperties

        public void InitializeTrayIconAndProperties()
        {
            serviceStatus = _serviceManager.GetServiceStatus();

            //Set the Tray icon
            if (serviceStatus == ServiceControllerStatus.Running)
                notifyTrayIcon.Icon = Properties.Resources.TrayIconRunning;
            else if (serviceStatus == ServiceControllerStatus.Stopped)
                notifyTrayIcon.Icon = Properties.Resources.TrayIconStopped;
            else
                notifyTrayIcon.Icon = Properties.Resources.TrayIconActive;

            //Setup context menu options
            trayContextMenu = new ContextMenuStrip();
            trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = ActionConstants.REFRESH, Text = "Refresh Status" });
            trayContextMenu.Items.Add("-");

            _startServiceItem = new ToolStripMenuItem() { Enabled = ServiceControllerStatus.Stopped.Equals(serviceStatus), Name = ActionConstants.START_SERVICE, Text = "Start Service" };
            trayContextMenu.Items.Add(_startServiceItem);

            _stopServiceItem = new ToolStripMenuItem() { Enabled = ServiceControllerStatus.Running.Equals(serviceStatus), Name = ActionConstants.STOP_SERVICE, Text = "Stop Service" };
            trayContextMenu.Items.Add(_stopServiceItem);

            trayContextMenu.Items.Add("-");
            trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = ActionConstants.SHOW_LOGS, Text = "Show Logs" });
            trayContextMenu.Items.Add("-");

            trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = "actionExit", Text = "Exit" });

            trayContextMenu.ItemClicked += trayContextMenu_ItemClicked;

            //Initialize the tray icon here
            this.notifyTrayIcon.ContextMenuStrip = trayContextMenu;
        }
开发者ID:electricneuron,项目名称:jonel.communicationservice,代码行数:34,代码来源:FormApp.cs

示例5: MonitorService

        internal void MonitorService()
        {
            serviceStatus = ServiceControllerStatus.Stopped;
            System.Threading.Thread.Sleep(3000);

            bool first = true;

            while (RunMonitor)
            {
                try
                {
                    ServiceControllerStatus status = PVServiceManager.GetServiceStatus();

                    if (status != serviceStatus || first || ForceRefresh)
                    {
                        SynchronizationContext.Post(new SendOrPostCallback(delegate
                                                                            {
                                                                                ServiceStatusChangeNotification(status);
                                                                            }), null);

                        //ServiceStatusChangeNotification(svc.Status);
                        first = ForceRefresh; // avoid race - do it twice
                        ForceRefresh = false;
                    }
                    serviceStatus = status;
                }
                catch (Exception)
                {
                    SynchronizationContext.Post(new SendOrPostCallback(delegate
                        {
                            ServiceStatusChangeNotification(ServiceControllerStatus.Stopped);
                        }), null);
                }
                System.Threading.Thread.Sleep(3000);
            }
        }
开发者ID:alberthoekstra,项目名称:PVBeanCounter,代码行数:36,代码来源:ManageService.cs

示例6: RestoreService

 private void RestoreService(ServiceControllerStatus previousStatus)
 {
     if (previousStatus == ServiceControllerStatus.Running) {
         controller.Start();
     } else if (previousStatus == ServiceControllerStatus.Paused) {
         controller.Pause();
     }
 }
开发者ID:siwater,项目名称:ssd_library,代码行数:8,代码来源:AgentController.cs

示例7: serviceTimer_Tick

		private void serviceTimer_Tick (object sender, EventArgs e) {
			try {
				lastError = null;
				lastStatus  = serviceController.Status;
			} catch (Exception ex) {
				lastStatus = ServiceControllerStatus.Paused;
				lastError = ex;
			}
			UpdateStatus ();
		}
开发者ID:pearjoint,项目名称:smoothio,代码行数:10,代码来源:MainForm.cs

示例8: ThrowUnableToChangeStatus

        private static void ThrowUnableToChangeStatus(string serviceName, ServiceControllerStatus status, Exception exception)
        {
            var message = "Unable to change " + serviceName + " status to " + Enum.GetName(typeof(ServiceControllerStatus), status);

            if (exception == null)
            {
                throw new InvalidOperationException(message);
            }

            throw new InvalidOperationException(message, exception);
        }
开发者ID:petarvucetin,项目名称:NServiceBus,代码行数:11,代码来源:ProcessUtil.cs

示例9: ToServiceStatus

		static ServiceStatus ToServiceStatus(ServiceControllerStatus status)
		{
			switch (status)
			{
				case ServiceControllerStatus.StopPending:
					return ServiceStatus.Stopped;
				case ServiceControllerStatus.Stopped:
					return ServiceStatus.Stopped;
				default:
				return ServiceStatus.Started;
			}
		}
开发者ID:pragmatrix,项目名称:Dominator,代码行数:12,代码来源:ServiceTools.cs

示例10: CheckStatus

		private bool CheckStatus(ServiceControllerStatus status)
		{
			try
			{
				this.service.Refresh();
				return this.service.Status == status;
			}
			catch (InvalidOperationException)
			{
				return false;
			}
		}
开发者ID:d1ce,项目名称:PhpVersionSwitcher,代码行数:12,代码来源:ServiceManager.cs

示例11: ServiceController

 internal ServiceController(string machineName, System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS_PROCESS status)
 {
     this.machineName = ".";
     this.name = "";
     this.displayName = "";
     this.eitherName = "";
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
     }
     this.machineName = machineName;
     this.name = status.serviceName;
     this.displayName = status.displayName;
     this.commandsAccepted = status.controlsAccepted;
     this.status = (ServiceControllerStatus) status.currentState;
     this.type = status.serviceType;
     this.statusGenerated = true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:ServiceController.cs

示例12: TranslateServiceStatus

 /// <summary>
 /// Maps the status of eam service to value specified in resources.
 /// </summary>
 /// <param name="status"></param>
 /// <returns></returns>
 public static String TranslateServiceStatus(ServiceControllerStatus status)
 {
     if (status == ServiceControllerStatus.Running)
         return Resources.Strings.EAMservice_Running;
     if (status == ServiceControllerStatus.Stopped)
         return Resources.Strings.EAMservice_Stop;
     if (status == ServiceControllerStatus.ContinuePending)
         return Resources.Strings.EAMservice_ContinuePending;
     if (status == ServiceControllerStatus.Paused)
         return Resources.Strings.EAMservice_Paused;
     if (status == ServiceControllerStatus.PausePending)
         return Resources.Strings.EAMservice_PausePending;
     if (status == ServiceControllerStatus.StartPending)
         return Resources.Strings.EAMservice_StartPending;
     if (status == ServiceControllerStatus.StopPending)
         return Resources.Strings.EAMservice_StopPending;
     return "";
 }
开发者ID:vinhdoan,项目名称:Angroup.demo,代码行数:23,代码来源:ServiceView.cs

示例13: ChangeServiceStatus

        /// <summary>
        /// Checks the status of the given controller, and if it isn't the requested state,
        /// performs the given action, and checks the state again.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="status"></param>
        /// <param name="changeStatus"></param>
        public static void ChangeServiceStatus(ServiceController controller, ServiceControllerStatus status, Action changeStatus)
        {
            if (controller.Status == status)
            {
                Logger.Debug(controller.ServiceName + " status is good: " + Enum.GetName(typeof(ServiceControllerStatus), status));
                return;
            }

            Logger.Debug(controller.ServiceName + " status is NOT " + Enum.GetName(typeof(ServiceControllerStatus), status) + ". Changing status...");

            changeStatus();

            var timeout = TimeSpan.FromSeconds(3);
            controller.WaitForStatus(status, timeout);
            if (controller.Status == status)
                Logger.Debug(controller.ServiceName + " status changed successfully.");
            else
                throw new InvalidOperationException("Unable to change " + controller.ServiceName + " status to " + Enum.GetName(typeof(ServiceControllerStatus), status));
        }
开发者ID:togakangaroo,项目名称:NServiceBus,代码行数:26,代码来源:ProcessUtil.cs

示例14: TrySetStatus

		private Task<bool> TrySetStatus(ServiceControllerStatus status, Action method)
		{
			return Task.Run(() =>
			{
				var timeSpan = TimeSpan.FromSeconds(WaitTime);

				try
				{
					method();
					this.service.WaitForStatus(status, timeSpan);
				}
				catch (System.ServiceProcess.TimeoutException) { }
				catch (InvalidOperationException)
				{
					Task.Delay(timeSpan).Wait(); // force-wait
				}

				return this.CheckStatus(status);
			});
		}
开发者ID:d1ce,项目名称:PhpVersionSwitcher,代码行数:20,代码来源:ServiceManager.cs

示例15: 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


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