启动服务和启动服务的状态 [英] status of started service and starting service
本文介绍了启动服务和启动服务的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道c#中启动服务和启动服务的状态.
我想使用此状态运行进度条,直到服务启动.
I want to know what will be the status of started service and starting service in c#.
I want to use this status to run progress bar till service started.
推荐答案
向您的项目中添加对 System.ServiceProcess 的引用,然后您可以使用ServiceController
类获取信息,如下所示:
Add a reference to System.ServiceProcess to your project and then you can get information using theServiceController
class, like this:
ServiceController controller = new ServiceController();
controller.MachineName = ".";
controller.ServiceName = "Tomcat6";
Console.WriteLine("Status {0}", controller.Status);
Console.WriteLine("CanPauseAndContinue {0}", controller.CanPauseAndContinue);
Console.WriteLine("CanShutdown {0}", controller.CanShutdown);
Console.WriteLine("CanStop {0}", controller.CanStop);
Console.WriteLine("DisplayName {0}", controller.DisplayName);
Console.WriteLine("ServiceType {0}", controller.ServiceType);
该类还具有用于启动和停止服务的方法.
请注意,您必须将名称而不是显示名称传递给Name
属性,您可以通过右键单击服务并选择属性来获得此名称.
希望这会有所帮助,
弗雷德里克(Fredrik)
The class also has methods for starting and stopping the service.
Note that you have to pass the name, not the display name, to the Name
property, you can get this by right-clicking your service and select Properties.
Hope this helps,
Fredrik
这篇关于启动服务和启动服务的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文