Get information about the internal state of a Windows service

I have a windows service that I am writing in .NET C #. The service will act as a file processor. It simply watches the File Created event directory and adds these files to the queue for processing. A separate thread draws files from the queue and processes them.

My question is, is there a way to request a windows service in order to get my โ€œstateโ€. I would like to be able to request a service in some way and see a list of files waiting in a queue, etc.

I know that this can be done on Linux via the / proc file system, and I was wondering if there was anything like that for Windows. Any tips / pointers would be greatly appreciated.

+6
source share
3 answers

If you are looking for a non-user interface (for example, to write names to a file or for standard output), you can use the ExecuteCommand method in the service.

ServiceController sc = new ServiceController("ServiceName"); sc.ExecuteCommand(255); 

It simply passes this command to your service, and your service will process it through OnCustomCommand

 protected override void OnCustomCommand(int command) { base.OnCustomCommand(command); if (command == 255 { ... // Your code here } } 

You may need to store the status of the queue / service in a static variable so that you can access it from the OnCustomCommand routine.

+3
source

You can create a hosted WCF service inside a Windows service with any methods necessary to access the state.

http://msdn.microsoft.com/en-us/library/ms733069.aspx

+2
source

WCF would be nice to do this, especially it can be hosted inside the Windows Service. Perhaps in your case it makes sense to use XML-RPC with WCF

0
source

Source: https://habr.com/ru/post/916287/


All Articles