Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concerns with long-running process on IIS

Concerns:

I have read through posts/blogs that describe IIS could recycle the app pool at any time. Does this mean (in terms of IIS recycling app pool) it would not matter if I make a call to a long running process synchronous or asynchronous, as IIS could recycle the app pool and terminate the long-running process? If this is the case, what are common paths to make sure this does not happen?

Example

public Task<ActionResult> LongRunningProcessAsync(SubmitFileModel aModel)

    {
        return Task.Run( () => LongRunningProcess( aModel) );
    }
like image 270
Luke G Avatar asked Oct 06 '22 18:10

Luke G


1 Answers

HostingEnvironment has a static method, RegisterObject, that allows you to place an object in the list of registered objects for the application.

According to Phil Haack...

When ASP.NET tears down the AppDomain, it will first attempt to call Stop method on all registered objects....When ASP.NET calls into this method, your code needs to prevent this method from returning until your work is done.

Alternatively, you could create a service that is not hosted by IIS.

like image 99
barry Avatar answered Oct 10 '22 02:10

barry