back

Small tip: use QueueBackgroundWorkItem for asynchronous work in ASP.NET

This is a small tip that I’m mainly publishing as a reminder to myself, but it could come in handy for someone else. Background processing tasks in ASP.NET are hard. At any time IIS could decide to recycle the application lifecycle. The usual solution is to farm out these tasks to a (Azure) queue and let some other machine (for example an Azure worker role) process that queue. However, with ASP.NET 4.5.2 Microsoft introduced the QueueBackgroundWorkItem method. This makes it possible to create small background processing tasks within the application lifecycle context. See the following (extremely simple) example:  

  • Caveats: A task started this way will only delay the recycling of the app pool for 30 seconds. So you need to complete your work within those 30 seconds. If not, the task will be killed.
  • You need ASP.NET 4.5.2.

See for more detail the following links: http://blog.simontimms.com/2014/05/23/background-tasks-in-asp-net-redux/ http://www.davidwhitney.co.uk/Blog/2014/05/09/exploring-the-queuebackgroundworkitem-in-asp-net-framework-4-5-2/ http://blogs.msdn.com/b/webdev/archive/2014/06/04/queuebackgroundworkitem-to-reliably-schedule-and-run-long-background-process-in-asp-net.aspx

GDPR Consent

The ICT Group website uses cookies for various functions in the website; Functional Cookies, Website Statistics, Personalised Advertising and Social Media. Advertising and Social Media cookies collect information about activities of individual users. This allows third parties to display personalised adverts to you and to allow you the option to share content from this site to Social Media platforms.

By continuing to use this website you are allowing us to place these cookies. The Cookie Settings voor de ICT Group website can be changed or revoked at any time. You can reach the settings through the Cookie Settings button as well as through the link in the footer of every page on this site.

Read our privacy policy here | Close this bar
Cookie Settings