Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I will provide an answer from a pragmatic perspective, rather than a direct answer to your question. This is particularly important when working on a real project (as opposed to homework). Short an...
Answer
#1: Initial revision
I will provide an answer from a pragmatic perspective, rather than a direct answer to your question. This is particularly important when working on a real project (as opposed to homework). ## Short answer Try to use a third-party library instead of reinventing the wheel. Defining and managing background jobs can be harder than expected due to aspects such as integration with the existing codebase, monitoring, cancellation, exception handling (retrial strategy). One such library in the .NET world (classic + Core) is [Hangfire](https://www.hangfire.io/). ## Longer answer Unless you are just toying with background services or tasks, these will have to integrate into a bigger project and besides the implementation details will become more important: - **concurrency** - what should happen if a job does not end and another instance starts? Should overlap be allowed? - **retrials** - sometimes the job fails. Does a retrial make sense? - **analytics** - is there a need to keep a history related to how jobs ran (time, errors etc.)? - **job information persistence** - does it make sense to persist the job information (i.e. scheduling information) somewhere like a database? - **dependency injection** - if tasks are related to already existing functionality, this must be "injected", so there is also the overhead of making background services work the DI container I am sure there are many other aspects, but the bottom line is that unless this is just for educational purposes, a third-party library will take care of many of the above aspects and more.