C#windows服务状态、启动和停止服务的操作是如何的呢?让我们开始吧:
C#windows服务状态、启动和停止服务1:
先引用System.ServiceProcess.dll
C#windows服务状态、启动和停止服务2:
在引用命名空间using System.ServiceProcess;
ServiceController sc = new ServiceController("Server");
//建立服务对象
//服务运行则停止服务
if (sc.Status.Equals(
ServiceControllerStatus.Running))
{
sc.Stop();
sc.Refresh();
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
C#windows服务状态、启动和停止服务的基本情况就向你介绍到这里,希望对你学习和了解C#windows服务状态、启动和停止服务有所帮助。
【编辑推荐】