C#windows服务状态改变操作浅析

开发 后端
C#windows服务状态、启动和停止服务是如何实现的呢?那么C#windows服务状态、启动和停止服务具体的步骤又是什么呢?让我们在本文中寻找答案。

C#windows服务状态、启动和停止服务的操作是如何的呢?让我们开始吧:

C#windows服务状态、启动和停止服务1:

先引用System.ServiceProcess.dll

C#windows服务状态、启动和停止服务2:

在引用命名空间using System.ServiceProcess;

  1. ServiceController sc = new ServiceController("Server");
  2.  
  3. //建立服务对象  
  4.  
  5. //服务运行则停止服务  
  6.  
  7.  if (sc.Status.Equals(  
  8.  
  9. ServiceControllerStatus.Running))
  10.  
  11.  {  
  12.      sc.Stop();  
  13.  
  14.   sc.Refresh();  
  1.  
  2.  }  
  3.  
  4. //服务停止则启动服务  
  5.  
  6.  if ((sc.Status.Equals(  
  7.  
  8. ServiceControllerStatus.Stopped)
  9.  
  10. ) || (sc.Status.Equals(
  11.  
  12. ServiceControllerStatus.StopPending)
  13.  
  14. ))  
  15.  {  
  16.  
  17.      sc.Start();  
  18.  
  19.      sc.Refresh();  
  20.  
  21.  } 

C#windows服务状态、启动和停止服务的基本情况就向你介绍到这里,希望对你学习和了解C#windows服务状态、启动和停止服务有所帮助。

【编辑推荐】

  1. C#Windows服务程序开发软件功能需求
  2. C#Windows服务程序开发之Windows服务浅析
  3. C#Windows服务程序安装浅析
  4. C#Windows服务程序开发的体会
  5. C#启动windows服务的方法浅析
责任编辑:仲衡 来源: 百度空间
相关推荐

2009-08-14 14:25:09

Windows服务程序

2009-08-14 15:06:08

Windows服务程序

2009-08-14 15:47:18

C#Windows服务

2009-08-14 15:19:38

Windows服务程序Windows服务

2009-08-14 14:17:16

C#Windows服务

2009-08-14 10:50:09

Windows服务介绍

2009-08-14 14:53:55

WINDOWS服务交互

2009-08-14 11:15:19

文件监视C#Windows服务

2009-08-14 15:54:50

Windows服务程序C#Windows服务

2009-08-14 16:24:00

Windows服务程序

2009-08-14 14:45:03

C#Windows服务

2009-08-14 16:48:39

C#Windows服务

2009-08-14 17:55:52

C#Windows应用

2009-08-14 10:42:16

Timer控件的使用C#windows服务

2009-08-14 13:41:13

C#Windows服务

2009-08-14 11:00:16

C#创建Windows

2009-08-14 18:04:59

C#Windows应用

2009-08-14 16:02:50

C#启动windows

2009-08-14 17:27:30

C#Windows应用

2009-08-14 17:36:20

C#Windows应用
点赞
收藏

51CTO技术栈公众号