user1178399
user1178399

Reputation: 1118

Using of Backgroundworker in asp.net

Can anyone explain is it possible to use Backgroundworker in asp.net? If it's a bad idea, then why?

Upvotes: 1

Views: 9635

Answers (2)

Amr Elgarhy
Amr Elgarhy

Reputation: 68902

Nothing good or bad in general, it is all based on how you will use it, and if you will consider any expected future issues, I find that this article and links inside it is very good http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx

A few years back Phil Haack wrote a great article on the dangers of recurring background tasks in ASP.NET. In it he points out a few gotchas that are SO common when folks try to do work in the background. Read it, but here's a summary from his post.

An unhandled exception in a thread not associated with a request will take down the process. If you run your site in a Web Farm, you could end up with multiple instances of your app that all attempt to run the same task at the same time. The AppDomain your site runs in can go down for a number of reasons and take down your background task with it. If you think you can just write a background task yourself, it's likely you'll get it wrong. I'm not impugning your skills, I'm just saying it's subtle. Plus, why should you have to?

There's LOT of great ways for you to do things in the background and a lot of libraries and choices available.

Some ASP.NET apps will be hosted in IIS in your data center and others will be hosted in the Azure cloud. The spectrum of usage is roughly this, in my opinion:

General: Hangfire (or similar similar open source libraries) used for writing background tasks in your ASP.NET website Cloud: Azure WebJobs A formal Azure feature used for offloading running of background tasks outside of your Website and scale the workload Advanced: Azure Worker Role in a Cloud Service scale the background processing workload independently of your Website and you need control over the machine There's lots of great articles and videos on how to use Azure WebJobs, and lots of documentation on how Worker Roles in scalable Azure Cloud Services work, but not a lot about how your hosted ASP.NET application and easily have a background service. Here's a few.

Upvotes: 1

Related Questions