开发者

Communicating with / sending instructions to Windows services?

开发者 https://www.devze.com 2023-03-16 08:46 出处:网络
We have a solution written by an outside contractor whereby a .net Windows Service runs continually, monitoring the system time, and, during the night, when there is very little activity, executes a l

We have a solution written by an outside contractor whereby a .net Windows Service runs continually, monitoring the system time, and, during the night, when there is very little activity, executes a long task, signals when the task has completed, then returns to monitoring the time until the next night.

There is currently no way to monitor or query the status of the process being run by the service, though we can query the service itself to see whether it is being run by Windows, or not.

In the event of a failure, the contractor provided us with a separate executable which can also run the same task.

The problem is, there is no way to know whether the service is currently executing the long task, and it is simply incomplete, or whether it has entered some kind of failure state, meaning that the standalone executable might easily be run in开发者_StackOverflow error, because the service is still processing the task.

Ultimately I would like to be able to send queries to the service, find out its state, and give it instructions while it is running.

What method should I use to start sending and receiving these messages?


There are several methods of Inter-process communication available to you, the most obvious choices that spring to mind are Named Pipes or Sockets.

Either of those would work fine, however rather than trying to implement these directly I would instead recommend that you host a WCF Service (inside the Windows service) and use this for interprocess communication.

WCF Services can be seamlessly configured to use either Sockets or Named Pipes (as well as a range of less suitable options) as the underlying transport mechanism, as well as simplifying the development of IPC (Inter Process Communication) systems.

There is a wealth of information on WCF Services and how to implement a WCF Service on the web - just try Google.

(If for some reason you are using .Net 2.0 instead of .Net 3.5 or above then you should instead look at .Net Remoting - it is essentially the predecessor to WCF and works in a completely different way, however basically achieves the same thing).


You can host a WCF service inside it and use this service to query the status

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号