Search code examples
projects-and-solutionsapplication-design

C# What is my best option? Service/Application/Multiple Applications


I am developing a solution that requires a number of tasks to be completed at various times. Example:

  • Task 1 - Monitor mailbox, process mail items
  • Task 2 - Monitor mailbox (different folder), process mail items
  • Task 3 - Generate PDF reports
  • Task 4 - Monitor folder, distribute files via email as attachments when new ones arrive.

I have already implemented the solution, however, it was basically just a quick fix to get the thing running. Now that it is up, I want to revisit the current setup and improve it so it is as efficient as possible.

For the current solution I have created a sepearate application for each different task and used the Task Scheduler to execute them at specific times.

  • Task 1 is a console application that runs on a scheduled task every 5 minutes
  • Task 2 is a console application that runs on a scheduled task every 5 minutes (2 minutes after the first application this is because Task 1 will move emails into the folder Task 2 is monitoring)
  • Task 3 is run at 5am every day as a runonce application on a scheduled task
  • Task 4 is running indefinetly.

My question is, does this seem like a reasonable approach for a solution to this type of application? Do some of the tasks seem better as a service rather than an application?


Solution

  • A service sounds like the right way to approach this.

    Long running subtasks such as PDF generation are well suited to perform using the asynchronous programming method, i.e. using worker threads that call back to the parent thread upon completion. This way the monitor tasks can run independently of the action tasks.