如何在Windows中启动/停止索引服务 [英] How to start/stop indexing services in windows
本文介绍了如何在Windows中启动/停止索引服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用C#在Windows中启动/停止索引服务.怎么做?
启动服务后,我想创建目录和范围..
I would like to start/stop indexing services in windows using C#. How to do it?
After starting service I would like to create catalog and scope ..
推荐答案
请看以下示例: ^ ]
Have a look at this example: Start, Stop and Restart Windows Service [C#][^]
start
start
public static void StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
}
停止
stop
public static void StopService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
}
catch
{
// ...
}
}
这篇关于如何在Windows中启动/停止索引服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文