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


C# ServiceController.Stop方法代码示例

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


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

示例1: RestartSB

            public static void RestartSB()
            {
                string ServiceName = "SolutionBuilder Core Service";

                ServiceController service = new ServiceController();
                service.MachineName = ".";
                service.ServiceName = ServiceName;
                string status = service.Status.ToString();
                try
                {
                    if (service.Status == ServiceControllerStatus.Running)
                    {
                        service.Stop();
                        service.WaitForStatus(ServiceControllerStatus.Stopped);
                    }
                    //Recycle App Pool
                    try
                    {
                        RecycleAppPool();
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.Message);
                    }
                    if (service.Status == ServiceControllerStatus.Stopped)
                    {
                        service.Start();
                        service.WaitForStatus(ServiceControllerStatus.Running);
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
开发者ID:iSmartCon,项目名称:ToolBox,代码行数:35,代码来源:Plugin.cs

示例2: runServiceCheck

        public void runServiceCheck()
        {
            Utils util = new Utils();
            ServiceController sc = null;
            try
            {
                sc = new ServiceController(serviceName);

                switch (sc.Status)
                {
                    case ServiceControllerStatus.Running:
                        break;
                    case ServiceControllerStatus.Stopped:
                        sc.Start();
                        util.writeToLogFile("service checker starting "+serviceName);
                        break;
                    case ServiceControllerStatus.Paused:
                        sc.Stop();
                        sc.Start();
                        util.writeToLogFile("service checker starting " + serviceName);
                        break;
                    case ServiceControllerStatus.StopPending:
                        sc.Stop();
                        sc.Start();
                        util.writeToLogFile("service checker starting " + serviceName);
                        break;
                    case ServiceControllerStatus.StartPending:
                        sc.Stop();
                        sc.Start();
                        util.writeToLogFile("service checker starting " + serviceName);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                util.writeEventLog(e.Message);
                util.writeEventLog(e.StackTrace);
            }
            finally
            {
                try
                {
                    if (sc != null) sc.Close();

                } catch (Exception) {}
            }
        }
开发者ID:damico,项目名称:open-audit,代码行数:49,代码来源:CheckServiceThreadImpl.cs

示例3: RestartSmartComService

		/// <summary>
		/// Перезапустить службу SmartCOM.
		/// </summary>
		/// <param name="timeout">Ограничение по времени для перезапуска службы SmartCOM.</param>
		public static void RestartSmartComService(TimeSpan timeout)
		{
			var service = new ServiceController("SmartCom2");

			var msStarting = Environment.TickCount;
			var waitIndefinitely = timeout == TimeSpan.Zero;

			if (service.CanStop)
			{
				//this.AddDebugLog(LocalizedStrings.Str1891);
				service.Stop();
			}

			if (waitIndefinitely)
				service.WaitForStatus(ServiceControllerStatus.Stopped);
			else
				service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);

			//this.AddDebugLog(LocalizedStrings.Str1892);

			var msStarted = Environment.TickCount;
			timeout = timeout - TimeSpan.FromMilliseconds((msStarted - msStarting));

			//this.AddDebugLog(LocalizedStrings.Str1893);

			service.Start();

			if (waitIndefinitely)
				service.WaitForStatus(ServiceControllerStatus.Running);
			else
				service.WaitForStatus(ServiceControllerStatus.Running, timeout);

			//this.AddDebugLog(LocalizedStrings.Str1894);
		}
开发者ID:reddream,项目名称:StockSharp,代码行数:38,代码来源:SmartComService.cs

示例4: StopService

 public static void StopService(string i_ServiceName, int i_ServiceChangeTimeoutInSconds)
 {
     ServiceController service = new ServiceController(i_ServiceName);
     TimeSpan timeout = TimeSpan.FromSeconds(i_ServiceChangeTimeoutInSconds);
     service.Stop();
     service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
 }
开发者ID:ddotan,项目名称:Service.Restarter.Agent,代码行数:7,代码来源:ServiceUtils.cs

示例5: OnBeforeUninstall

 protected override void OnBeforeUninstall(IDictionary savedState)
 {
     base.OnBeforeUninstall(savedState);
     using (var serviceController = new ServiceController(serviceInstaller1.ServiceName, Environment.MachineName)
         )
         serviceController.Stop();
 }
开发者ID:SameerOmar,项目名称:InkMon,代码行数:7,代码来源:ServiceInstaller.cs

示例6: dbCopyButton_Click

        private void dbCopyButton_Click(object sender, EventArgs e)
        {
            if(dbNameTextBox.Text!= null && destFolderTextBox.Text!= null)
            {
                string filename;
                int index = dbNameTextBox.Text.LastIndexOf('\\');
                if(index != -1)
                    filename = dbNameTextBox.Text.Substring(index+1);
                else
                    filename = dbNameTextBox.Text;

                ServiceController service = new ServiceController("DpFamService");
                if (service.Status.Equals(ServiceControllerStatus.Running))
                {
                    service.Stop();
                    service.WaitForStatus(ServiceControllerStatus.Stopped);
                }

                try
                {
                    System.IO.File.Copy(dbNameTextBox.Text, destFolderTextBox.Text + "\\" + filename);
                    System.IO.File.Delete(dbNameTextBox.Text);

                    MessageBox.Show("Database Copied Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    CLogger.WriteLog(ELogLevel.ERROR, "Error while copying file to " + destFolderTextBox.Text + " " + exc.Message);
                    MessageBox.Show("Could not Copy Database", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                service.Start();
            }
        }
开发者ID:tkhurana,项目名称:File-Access-Monitor,代码行数:33,代码来源:SettingsWindow.cs

示例7: StopService

        public void StopService(string type, string serviceName, string machineName)
        {
            if (type == "Service")
            {
                try
                {
                    using (var sc = new ServiceController(serviceName, "."))
                    {
                        sc.Stop();
                        sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(15));
                    }
                }
                catch (Exception ex)
                {
                    var test = ex.Message;
                    throw;
                }
            }
            else if (type == "AppPool")
            {
                StopApplicationPool(machineName, serviceName);
            }
            else if (type == "Website")
            {
                StopApplication(machineName, serviceName);
            }



        }
开发者ID:Robin--,项目名称:Akka.Cluster.Monitor,代码行数:30,代码来源:ServiceStatusController.cs

示例8: Main

        static void Main()
        {
            ////Se inician Servicios
            //ServiceController sMyDNSSEC = new ServiceController();
            //sMyDNSSEC.ServiceName = "MyDnsSecService";
            //sMyDNSSEC.Start();
            //sMyDNSSEC.WaitForStatus(ServiceControllerStatus.Running);
            //ServiceController sUnbound = new ServiceController();
            //sUnbound.ServiceName = "UnboundService";
            //sUnbound.Start();
            //sUnbound.WaitForStatus(ServiceControllerStatus.Running);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            frmMainConfDNSRES.ServicesEstatus = true;

            Application.Run(new frmMainConfDNSRES());
            if (frmMainConfDNSRES.ServicesEstatus == false)
            {
                //Se detienen Servicios
                ServiceController stopMyDNSSEC = new ServiceController();
                stopMyDNSSEC.ServiceName = "MyDnsSecService";
                stopMyDNSSEC.Stop();
                stopMyDNSSEC.WaitForStatus(ServiceControllerStatus.Stopped);
                ServiceController stopUnbound = new ServiceController();
                stopUnbound.ServiceName = "UnboundService";
                stopUnbound.Stop();
                stopUnbound.WaitForStatus(ServiceControllerStatus.Stopped);
            }
        }
开发者ID:McJaml,项目名称:My-dns-sec,代码行数:29,代码来源:Program.cs

示例9: OnTimedEvent

 /// <summary>
 /// This is the timer tick event for the timer loop
 /// </summary>
 private void OnTimedEvent(object source, ElapsedEventArgs e)
 {
     try
     {
         timer.Stop();
         if (!Utility.ServiceRunning("UniGuard12Server") && Utility.ServiceRunning("UniGuard12SiteWelfare"))
         {
             ServiceController sc = new ServiceController("UniGuard12SiteWelfare");
             sc.Stop();
         }
         else
         {
             if (running) return;
             running = true;
             // Run the method
             this.MonitorSites();
         }
     }
     catch (Exception ex)
     {
         Log.Error("Welfare checking error: " + ex.ToString());
     }
     finally
     {
         running = false;
         // Restart the timer
         timer.Start();
     }
 }
开发者ID:sandeeplocality,项目名称:UG12Server,代码行数:32,代码来源:SiteWelfareChecking.cs

示例10: RestartService

        public void RestartService(int timeoutMilliseconds)
        {
            log.Info(string.Format("Restarting {0}", serviceName));
            var service = new ServiceController(serviceName, machineName);
            try
            {
                int millisec1 = Environment.TickCount;
                TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

                service.Stop();
                service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
                log.Debug(string.Format("Stopped {0}", serviceName));
                // count the rest of the timeout
                int millisec2 = Environment.TickCount;
                timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - (millisec2 - millisec1));

                service.Start();
                service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                log.Debug(string.Format("Started  {0}", serviceName));
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
开发者ID:perryofpeek,项目名称:SvcRestart,代码行数:25,代码来源:SvcState.cs

示例11: StopService

        public void StopService()
        {
            Debug.PrintMessage(string.Format("Timeout = {0}ms.", _Timeout.TotalMilliseconds));
            Program.consoleWrite("Stopping " + _WUServiceName + " service");

            ServiceController sc = new ServiceController(_WUServiceName);

            try
            {
                sc.Stop();
                sc.WaitForStatus(ServiceControllerStatus.Stopped, _Timeout);
                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80131509)
                {
                    Console.WriteLine("Already stopped.");
                    RestartService = false;
                }
                else
                {
                    Console.WriteLine("\nAn error occured during stopping Windows Update service. Unable to continue.\nError code: {0}\nMore information: {1}", ex.HResult.ToString("X"), ex.InnerException);
                    Environment.Exit(ex.HResult);
                }
            }
        }
开发者ID:LucasM99,项目名称:WUTest,代码行数:27,代码来源:ServiceManager.cs

示例12: OnTimedEvent

        /// <summary>
        /// This is the timer tick event for the timer loop
        /// </summary>
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            try
            {
                // Stop the timer
                timer.Stop();
                if (!Utility.ServiceRunning("UniGuard12Server") && Utility.ServiceRunning("UniGuard12SiteLoop"))
                {
                    ServiceController sc = new ServiceController("UniGuard12SiteLoop");
                    sc.Stop();
                }
                else
                {
                    if (running) return;
                    running = true;

                    // Run the method
                    this.MonitorLoops();
                }
            }
            catch (Exception ex)
            {
                // Catch any exceptions in the stack
                Log.Error(ex.ToString());
            }
            finally
            {
                running = false;
                // Restart the timer
                timer.Start();
            }
        }
开发者ID:sandeeplocality,项目名称:UG12Server,代码行数:35,代码来源:SiteLoopMonitor.cs

示例13: Execute

        public Command Execute()
        {
            var service = new ServiceController("PlexConnect");
            try
            {
                TimeSpan timeout = TimeSpan.FromMilliseconds(10000);

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

                if (service.Status == ServiceControllerStatus.Stopped)
                {
                    service.Start();
                    service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                }
            }
            catch (Exception ex)
            {
                command.Message = ex.Message;
            }
            command.Message = "Plex Connect Restarted";

            Notify();
            return command;
        }
开发者ID:juanlurie,项目名称:Tools,代码行数:28,代码来源:PlexConnect.cs

示例14: StopService

 public void StopService()
 {
     using (ServiceController controller = new ServiceController(serviceName))
     {
         controller.Stop();
     }
 }
开发者ID:breslavsky,项目名称:queue,代码行数:7,代码来源:ServiceManager.cs

示例15: Restart

        public bool Restart(string[] args, TimeSpan timeout)
        {
            var service = new ServiceController(serviceName);
            try
            {
                var millisec1 = TimeSpan.FromMilliseconds(Environment.TickCount);

                service.Stop();
                service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
                Log.Info("Service is stopped");

                // count the rest of the timeout
                var millisec2 = TimeSpan.FromMilliseconds(Environment.TickCount);
                timeout = timeout - (millisec2 - millisec1);

                service.Start(args);
                service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                Log.Info("Service has started");
                return true;
            }
            catch (Exception ex)
            {
                Log.ErrorException("Cannot restart service " + serviceName, ex);
                return false;
            }
        }
开发者ID:Bloomie,项目名称:murano-agent,代码行数:26,代码来源:ServiceManager.cs


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