user204588
user204588

Reputation: 1633

ASP.NET long running task ideas

Very often I have to send data to and from third party accounting systems from asp.net sites using SQL server. The data imports usually take awhile and I'm trying to find the best method to handle the long running tasks with the ability to update the user if they want to see how it's doing. My questions are what are some of the pros and cons with the methods below and what do you recommend and why?

Upvotes: 2

Views: 1832

Answers (2)

jzonthemtn
jzonthemtn

Reputation: 3414

If the job takes more than a few minutes, I would recommend the job be added to a database where the status of the job could be updated by the process doing the work. You could implement a small command line application or Windows service (they really aren't too bad to make, see Writing a Useful Windows Service in .NET in Five Minutes) that monitors the database for new jobs. When it finds one it picks it up and updates its status as it goes. The end user can be redirected to a page that lists each job and its progress. When the job is complete the database row is updated and the application waits for a new job to come along.

Upvotes: 1

OfirYaron
OfirYaron

Reputation: 157

It's really a question of how critical is that background task you wish to perform and what triggers it. if its a recurrent event that happen in a per-known interval I find that creating a Timer on the application thread (global.asax) is best like the following example:

Implementing Recurring Background Tasks In ASP.NET - http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx

To cover the client side an iframe can do the trick but Ajax request will be a bit more elegant.

as long as you sign your task on HostingEnvironment.RegisterObject, pool recycling will not intrude your job.

Upvotes: 0

Related Questions