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


C# ServiceController.Stop方法代码示例

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


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

示例1: Main

	static void Main()
	{
		ServiceController myservice = new ServiceController();
		myservice.ServiceName = "Marimba";
		string svcname = myservice.Status.ToString();
	
	  if(svcname.Equals("Running"))
	  {
	  	Console.WriteLine("Service is Running");
	  	Console.WriteLine("Stop Services");
	  	
	  	myservice.Stop();
	  	Console.WriteLine("Service Stopped");
	  }
	  else
	  {
	  	Console.WriteLine("Starting service");
	  	myservice.Start();
	  }
	}
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:20,代码来源:example1.cs

示例2: StopAndStart

        public void StopAndStart()
        {
            var controller = new ServiceController(_testService.TestServiceName);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            for (int i = 0; i < 2; i++)
            {
                controller.Stop();
                controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);

                controller.Start();
                controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Running, controller.Status);
            }
        }
开发者ID:rendle-labs,项目名称:corefx,代码行数:16,代码来源:ServiceControllerTests.cs

示例3: StartWithArguments

        public void StartWithArguments()
        {
            var controller = new ServiceController(_testService.TestServiceName);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            controller.Stop();
            controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
            Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);

            var args = new[] { "a", "b", "c", "d", "e" };
            controller.Start(args);
            controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            // The test service writes the arguments that it was started with to the _testService.TestServiceRegistryKey.
            // Read this key to verify that the arguments were properly passed to the service.
            string argsString = Registry.GetValue(_testService.TestServiceRegistryKey, "ServiceArguments", null) as string;
            Assert.Equal(string.Join(",", args), argsString);
        }
开发者ID:rendle-labs,项目名称:corefx,代码行数:19,代码来源:ServiceControllerTests.cs

示例4: RestartC2RSerivce

 public static void RestartC2RSerivce()
 {
     const string serviceName = "ClickToRunSvc";
     var service = new ServiceController(serviceName);
     service.Stop();
     service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 5));
     service.Start();
     service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 5));
 }
开发者ID:OfficeDev,项目名称:Office-IT-Pro-Deployment-Scripts,代码行数:9,代码来源:InstallOffice.cs


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