Why do background tasks in an ASP.
The main consideration is to use background tasks to handle CPU or IO intensive computations.
Here are some common background tasks:
- Lots of reminders and news emails to send
- Image and video processing (e.g. batch creation of thumbnails, format conversion)
- Import large amounts of data or export data from external files (RSS aggregation)
- File operations (create archive, clean up temporary files, log file maintenance)
- Generate automated reports at timed intervals
- Database Maintenance
- ......
Asp. NET does not know any background thread such as a timer or anything else, it knows only the operations associated with the request. In fact, running certain tasks in the background for a long time is not something that Web server does, and there are usually other ways to avoid this, such as using the console application and Windows Task Manager, or using Windows services.
But sometimes considering that you don't want to deploy servers separately: development, deployment is simple, scaling is simple, saving money, do you really want to perform background tasks in an ASP.
Method 1, Hostingenvironment.queuebackgroundworkitem
Lets you dispatch small background tasks, ASP. NET keeps track of these tasks and prevents IIS from abruptly ending the worker process until it finishes. This allows an ASP. NET application to reliably dispatch asynchronous tasks.
However, the project needs to be configured to use. NET 4.5.2
Method 2, Hangfire
Hangfire is an open-source class library that provides an easy way to perform background long-running tasks in ASP. This class library requires some additional storage support, Sqlserver,redis or MSMQ. Hangfire's information is in http://hangfire.io/.
Performing background tasks in an ASP.