You have a need for a background task that would run periodically (regardless of requests to a web application) and perform "useful work": collecting some data, sending notifications, etc. As in most cases, there are many possible solutions. I will offer a couple with whom I met in practice.
1) Background streams directly in a web application. In this case, your application (MVC site or Web service) starts up the necessary background threads that are idle for a specified amount of time and then do their work after it expires. After executing the work, the thread again "falls asleep" for a specified period of time. The advantages of this approach:
- Relatively easy implementation
- No need to create separate applications
But there are significant drawbacks:
- Additional Web application load
- Increased Web application vulnerability (due to unhandled exceptions in threads, for example)
If you decide to try this approach, be sure to check out this article: The Dangers of Implementing Recurring Background Tasks In ASP.NET . It describes the possible risks and example implementation (English language).
2) A separate console application that performs the necessary task and runs on the scheduler according to a predetermined schedule (a similar option is to create your own Windows service). Pros:
- Web application download from additional work
- Ability to run on another machine
Minuses:
- Requires the creation of a separate application and its configuration