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


C# ServiceController.Close方法代码示例

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


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

示例1: ServiceInstaller_Committed

 /// <summary>
 /// Handles the Committed event of the ServiceInstaller control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Configuration.Install.InstallEventArgs"/> instance containing the event data.</param>
 private void ServiceInstaller_Committed(object sender, InstallEventArgs e)
 {
     using (var service = new ServiceController(this.ServiceInstaller.ServiceName))
     {
         service.Start();
         service.WaitForStatus(ServiceControllerStatus.Running);
         service.Close();
     }
 }
开发者ID:Oslo-Lions-Elektroniske-Sportsklubb,项目名称:TS3-Bot,代码行数:14,代码来源:ProjectInstaller.cs

示例2: serviceInstaller1_BeforeUninstall

 private void serviceInstaller1_BeforeUninstall(object sender, InstallEventArgs e)
 {
     ServiceController sc = new ServiceController("Ezector Thinkingcap FTP");
     if (sc.Status == ServiceControllerStatus.Running)
     {
         sc.Stop();
         sc.WaitForStatus(ServiceControllerStatus.Stopped);
         sc.Close();
     }
 }
开发者ID:naveen-thinkingcap,项目名称:FTPWindowsService,代码行数:10,代码来源:ProjectInstaller.cs

示例3: btnRestart_Click

        private void btnRestart_Click(object sender, RoutedEventArgs e)
        {
            ServiceStruct ss = (ServiceStruct)lv.SelectedItem;

            ServiceController sc = new ServiceController(ss.name);
            sc.Stop();
            sc.WaitForStatus(ServiceControllerStatus.Stopped);
            sc.Start();
            sc.WaitForStatus(ServiceControllerStatus.Running);
            sc.Close();

            GetAllServices();
        }
开发者ID:3gbywork,项目名称:WindowsServicesManager,代码行数:13,代码来源:MainWindow.xaml.cs

示例4: checkServiceInstallation

 /// <summary>
 /// Verifies if the Window service with the given name is installed.
 /// </summary>
 /// <param name="serviceName"></param>
 /// <returns>true if the service is installed properly. false otherwise</returns>
 public static bool checkServiceInstallation(string serviceName)
 {
     bool exists = false;
     try
     {
         ServiceController sc = new ServiceController(serviceName);
         sc.Refresh(); //just a dummy call to make sure the service exists.
         sc.Close();
         sc = null;
         exists = true;
     }
     catch
     {}
     return exists;
 }
开发者ID:abhishek-kumar,项目名称:AIGA,代码行数:20,代码来源:ServiceHelper.cs

示例5: Start

        public void Start(string serviceName)
        {
            _logger.Log(String.Format("Starting '{0}' Service ...", serviceName));
            var serviceController = new ServiceController(serviceName);
            if (serviceController.Status == ServiceControllerStatus.Running)
            {
                _logger.Log(String.Format("'{0}' service already started.", serviceName));
                return;
            }

            serviceController.Start();
            serviceController.WaitForStatus(ServiceControllerStatus.Running);

            serviceController.Close();
            _logger.Log(String.Format("Service '{0}' started and now running ...", serviceName));
        }
开发者ID:rackerlabs,项目名称:openstack-guest-agents-windows-xenserver-old,代码行数:16,代码来源:ServiceStarter.cs

示例6: CheckServiceInstallation

 /// <summary>
 /// Verifies if the Window service with the given name is installed.
 /// </summary>
 /// <param name="serviceName">Name of the service.</param>
 /// <returns>
 /// true if the service is installed properly. false otherwise
 /// </returns>
 public static bool CheckServiceInstallation(string serviceName)
 {
     bool exists = false;
     ServiceController sc = null;
     try
     {
         sc = new ServiceController(serviceName);
         sc.Refresh(); //just a dummy call to make sure the service exists.
         exists = true;
     }
     finally
     {
         if (sc != null)
             sc.Close();
         sc = null;
     }
     return exists;
 }
开发者ID:JamesTryand,项目名称:alchemi,代码行数:25,代码来源:ServiceHelper.cs

示例7: OnBeforeUninstall

        protected override void OnBeforeUninstall(IDictionary savedState)
        {
            ServiceController service = new ServiceController(serviceInstaller.ServiceName);

            try
            {
                if (service.Status == ServiceControllerStatus.Running)
                {
                    service.Stop();
                    service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 0, 10));
                    service.Close();
                }
            }
            finally
            {
                base.OnBeforeUninstall(savedState);
            }
        }
开发者ID:RiceTea,项目名称:HardwareMonitor,代码行数:18,代码来源:ProjectInstaller.cs

示例8: OnCustomCommand

 /// <summary>
 /// 执行自定义重置命令
 /// </summary>
 /// <param name="command"></param>
 protected override void OnCustomCommand(int command)
 {
     if (200 != command || isTmRunning)
         return;
     isTmRunning = true;
     ServiceController ctrl = new ServiceController("Granity文件服务");
     try
     {
         LogMessage("守护Granity文件服务", null, EventLogEntryType.Information);
         try { ctrl.Stop(); }
         catch { }
         Thread.Sleep(new TimeSpan(0, 1, 0));
         ctrl.Start();
         Thread.Sleep(new TimeSpan(0, 1, 0));
     }
     catch { }
     ctrl.Close();
     isTmRunning = false;
 }
开发者ID:thisisvoa,项目名称:GranityApp2.5,代码行数:23,代码来源:ServiceWatch.cs

示例9: Stop

        public void Stop(string serviceName)
        {
            _logger.Log(String.Format("Stopping Service '{0}' ...", serviceName));

            var serviceController = new ServiceController(serviceName);
            if (serviceController.Status == ServiceControllerStatus.Stopped)
            {
                _logger.Log(String.Format("Service '{0}' already stopped.", serviceName));
                return;
            }

            if (!serviceController.CanStop)
                throw new ApplicationException(
                    String.Format("Service '{0}' can't be stop at this time, please try again later", serviceName));

            serviceController.Stop();
            serviceController.WaitForStatus(ServiceControllerStatus.Stopped);

            serviceController.Close();

            _logger.Log(String.Format("Service '{0}' successfully stopped.", serviceName));
        }
开发者ID:rackerlabs,项目名称:openstack-guest-agents-windows-xenserver-old,代码行数:22,代码来源:ServiceStopper.cs

示例10: StartStopService

        private void StartStopService(bool state)
        {
            ServiceController service = new ServiceController("AlarmworkflowService");
            try
            {
                if (state)
                {
                    Log.Write("Starting service...");
                    try
                    {
                        service.Start();
                        service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 30));
                        Log.Write("Service started.");
                    }
                    catch (System.ServiceProcess.TimeoutException)
                    {
                        Log.Write("Service not started. Please check the Windows Eventlog");
                    }

                }
                else
                {
                    Log.Write("Stopping service...");

                    if (service.Status == ServiceControllerStatus.Running)
                    {
                        service.Stop();
                        service.WaitForStatus(ServiceControllerStatus.Stopped);
                    }
                    service.Close();

                    Log.Write("Service stopped.");
                }
            }
            catch (InvalidOperationException)
            {
                // This exception is ok - it occurs if the service does not exist
            }
        }
开发者ID:Knatter33,项目名称:AlarmWorkflow,代码行数:39,代码来源:StartStopServiceTask.cs

示例11: Start

        public void Start(string serviceName)
        {
            try
            {
                _logger.Log(String.Format("Starting '{0}' Service ...", serviceName));
                var serviceController = new ServiceController(serviceName);
                if (serviceController.Status == ServiceControllerStatus.Running)
                {
                    _logger.Log(String.Format("'{0}' service already started.", serviceName));
                    return;
                }

                serviceController.Start();
                serviceController.WaitForStatus(ServiceControllerStatus.Running);

                serviceController.Close();
                _logger.Log(String.Format("Service '{0}' started and now running ...", serviceName));
            }
            catch (Exception ex)
            {
                _logger.Log(string.Format("An error occured trying to start the {0} service: {1}", serviceName, ex));
            }
        }
开发者ID:rackerlabs,项目名称:openstack-guest-agents-windows-xenserver,代码行数:23,代码来源:ServiceStarter.cs

示例12: StartService

 public static void StartService(string name)
 {
     ServiceController sc = new ServiceController(name);
     try
     {
         if (sc != null && sc.Status == ServiceControllerStatus.Stopped)
         {
             sc.Start();
         }
         sc.WaitForStatus(ServiceControllerStatus.Running);
         sc.Close();
     }
     catch (Exception)
     {
     }
 }
开发者ID:BenjaOtero,项目名称:trend-gestion-desktop,代码行数:16,代码来源:UtilVarios.cs

示例13: StartIfNeeded

        // Method to start the service automatically after installation
        private void StartIfNeeded(object sender, InstallEventArgs e)
        {
            // Do we need to do any work?
            if (!m_startOnInstall)
                return;

            try
            {
                TimeSpan waitTo = new TimeSpan(0, 0, m_startTimeout);

                // Get a handle to the service
                ServiceController sc = new ServiceController(base.ServiceName);

                // Start the service and wait for it to start
                sc.Start();
                sc.WaitForStatus(ServiceControllerStatus.Running, waitTo);

                // Be good and release our handle
                sc.Close();

                LogInstallMessage(EventLogEntryType.Information, m_logMessagePrefix + " Service Started");

            }
            // Catch all exceptions
            catch (Exception ex)
            {
                LogInstallMessage(EventLogEntryType.Error, m_logMessagePrefix + ex.Message);
            }
        }
开发者ID:rmc00,项目名称:gsf,代码行数:30,代码来源:ServiceInstallerEx.cs

示例14: StartService

 public static void StartService(string serviceName, string serverName, int timeoutSec)
 {
     try
     {
         ServiceController service = new ServiceController(serviceName, serverName);
         if (service.Status == ServiceControllerStatus.Stopped || service.Status == ServiceControllerStatus.StartPending)
         {
             try
             {
                 if (service.Status == ServiceControllerStatus.Stopped)
                 {
                     Log.Info("argustv: service {0} is stopped, so we try start it now...", serviceName);
                     service.Start();
                 }
                 service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, timeoutSec));
             }
             catch (Exception ex)
             {
                 Log.Error("argustv: starting service {0} failed, {1}", serviceName, ex.Message);
             }
         }
         Log.Info("argustv: service {0} - current status: {1}", serviceName, service.Status.ToString());
         service.Close();
         service.Dispose();
     }
     catch
     {
         Log.Info("argustv: service {0} not found on {1}", serviceName, serverName);
     }
 }
开发者ID:Christoph21x,项目名称:ARGUS-TV,代码行数:30,代码来源:Utility.cs

示例15: StopService

		private void StopService()
		{
			var sc = new ServiceController(_Configuration.ServiceName);

			try
			{
				if (sc.CanStop)
				{
					if (sc.Status != ServiceControllerStatus.Stopped && sc.Status != ServiceControllerStatus.StopPending)
					{
						sc.Stop();
						sc.WaitForStatus(ServiceControllerStatus.Stopped, _ServiceControllerTimeout);
					}
				}
			}
			catch (System.ServiceProcess.TimeoutException)
			{
				Console.Write(string.Format(CultureInfo.InvariantCulture, "Could not stop the {0} service.", _Configuration.ServiceName));
			}
			finally
			{
				sc.Close();
			}
		}
开发者ID:Philo,项目名称:Revalee,代码行数:24,代码来源:CommandLineInstaller.cs


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