Radu
Radu

Reputation: 1066

C# MVC IIS long running requests

I have an C# MVC app. And one of the calls I know will take like 12 hours, I'm generating some reports.

I want to know if the IIS will keep the process running this long. If I'll do it async will it run and somehow put it away and let him run for this long?

Upvotes: 0

Views: 485

Answers (2)

bilpor
bilpor

Reputation: 3889

I'm assuming the report must be using something like SSRS. Why don't you create a batch job at the backend to run the reports at a specified time. Update a table with the status of the report and just poll the status at the front end. when Ready just download it. Imagine if your report had been running for 6 hours and it's reliant on the website being up. If someone re-starts the website that's 6 hours of processing gone.

Upvotes: 1

zaitsman
zaitsman

Reputation: 9499

In general, this is a very poor practice. Your app pool may be recycled for many reasons outside of your control. You would greatly benefit from processing this in an external process and then providing the user the results via IIS.

However, starting .net 4.5.2 (https://blogs.msdn.microsoft.com/dotnet/2014/05/05/announcing-the-net-framework-4-5-2/) you can use the HostingEnvironment.QueueBackgroundWorkItem API. The idea behind this is that the IIS will try to finish this work in case of a graceful shutdown of the app pool.

Upvotes: 2

Related Questions