Performing background tasks in an ASP.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.