When to Dispose of Static Resources in ASP.NET MVC Application Lifecycle

We have an IDisposable resource which is relatively expensive to instantiate, although it is stateless and thread safe. So ... we decided to wrap using the standard singleton pattern and reuse the single instance for all requests until the applet refines.

With that in mind, we still want to call Dispose () in a deterministic way whenever possible.

The question is ... What is the appropriate place to put such resources if we ever have the ability to be graceful in a closing script? For example...

For context, the application is ASP.NET MVC 4.

    protected void Application_Disposed(Object sender, EventArgs e)
    {
        CleanUpResources();
    }

      

Or...

    protected void Application_End(Object sender, EventArgs e)
    {
        CleanUpResources();
    } 

      

+3


source to share


2 answers


The surest way I know to link applications completed event IRegisteredObject

. I don't know about reliability Application_End

.



0


source


Is the resource managed or unmanaged? If it is controlled, use Application_End

, otherwise use Application_Disposed

. See https://msdn.microsoft.com/en-us/library/ms178473.aspx for details .



+1


source







All Articles