R – What are common Windows service design patterns

design-patternswindowswindows-services

Where can I find good information on common design patterns that might be employed when building a new Windows service?

**Update: I'm asking if there are common designs that are used when constructing a service.*

For example: I have seen a single task get executed on a timer (this seems very common when constructing a service). I've also seen 'queue workers' deployed as services. Are there other common design patterns when designing software to be run as a service?

Best Answer

A Windows service is merely a background process that is not tied to an interactive desktop (although it can optionally communicate with one). The uses for such a concept are many and varied. Common uses for a service (not mutually exclusive):

  • Listen for an incoming request from somewhere else (e.g. TCP, RPC, COM, HTTP) and act on it.
  • Schedule a task to occur at a certain time, at regular intervals, or when some other condition becomes true, e.g. watching the file system.

The only pattern I can think of that you should apply to all your services is: Separate out the part that decides when to do the work from the part that does the work. This will make it easier to unit test and re-use the various parts.