Search code examples
c#windows-services

How to have a sequence of Windows Services


The solution I am working on requires multiple processes that are built in multiple Windows services all built using C# running on .NET.

  • Service 1 : Extract data in files in a folder
  • Service 2 : Analyse data and put results in image file
  • Service 3 : Process images into another application
  • Service 4 : Generate report

Each service runs every hour. Everything works fine.

One of the requests now is to do all services as fast as possible. Therefore I want these services to run consecutively.

How to call one service from the other or have a pipeline that runs all services one after the other.


Solution

  • You could use FileSystemWatcher and use folders as simple queues between services. Also note, FileSystemWatcher might not be 100% Reliable: FileSystemWatcher vs polling to watch for file changes

    Might need to set the NotifyFilter to get the behaviour you want.

    You could also add a mutex to the service, that detects if it is already running perhaps, and consumes folder/file changes in one go.

    There are other heavier weight, fully featured message queues, but these might be overkill for your needs.