I have an application in C# (2.0 running on XP embedded) that is communicating with a 'watchdog' that is implemented as a Windows Service. When the device boots, this service typically takes some time to start. I'd like to check, from my code, if the service is running. How can I accomplish this?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Here you get all available services and their status in your local machine.
You can Compare your service with service.name property inside loop and you get status of your service. For details go with the http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx also http://msdn.microsoft.com/en-us/library/microsoft.windows.design.servicemanager(v=vs.90).aspx
I guess something like this would work:
Add
System.ServiceProcess
to your project references (It's on the .NET tab).Edit: There is also a method
sc.WaitforStatus()
that takes a desired status and a timeout, never used it but it may suit your needs.Edit: Once you get the status, to get the status again you will need to call
sc.Refresh()
first.Reference: ServiceController object in .NET.
Please have a look on the ServiceController object in .NET.