I have a static class in my ASP.NET app that I use to hold an application wide data processing class used to manage long running batch operations sent in by users. This should be a singleton object as it is quite a heavy object.
public static class WebGISGlobals
{
private static MultiStatutoryMapPrintProcessor _batchPrintProcessor;
public static MultiStatutoryMapPrintProcessor BatchPrintProcessor
{
get
{
if (_batchPrintProcessor == null)
{
_batchPrintProcessor = new MultiStatutoryMapPrintProcessor(
(string)ConfigurationManager.AppSettings["statPrintWebServiceUrl"], HttpContext.Current.Server.MapPath("~/downloads"));
}
return _batchPrintProcessor;
}
}
}
This processor class passes the batch tasks to the Threadpool for execution and all works well….
except, when the queue becomes empty and the processes stop the next time the singleton is requested using WebGISGlobals.BatchPrintProcessor to collect the task results the object is null and creates a new instance. This unfortunately loses me reference to the output files it produces.
I have tried using Application["BatchProcessor"] to store my class instance for all to reference but it has the same effect.
Nowhere in my code do I dispose the instance or set it as null so I am stuck.
Anyone have any bright ideas.
UPDATE:
After a suggestion from rsbarro I have run a stack trace on the thread execution and it does not show any exceptions being fired.
> WebFGH.DLL!FGH.Global.Application_End(object sender = {System.Web.HttpApplicationFactory}, System.EventArgs e = {System.EventArgs}) Line 167 C#
[Native to Managed Transition]
[Managed to Native Transition]
System.Web.dll!System.Web.HttpApplication.ProcessSpecialRequest(System.Web.HttpContext context = null, System.Reflection.MethodInfo method, int paramCount, object eventSource, System.EventArgs eventArgs, System.Web.SessionState.HttpSessionState session) + 0x110 bytes
System.Web.dll!System.Web.HttpApplicationFactory.FireApplicationOnEnd() + 0x56 bytes
System.Web.dll!System.Web.HttpApplicationFactory.Dispose() + 0x109 bytes
System.Web.dll!System.Web.HttpRuntime.Dispose() + 0x114 bytes
System.Web.dll!System.Web.HttpRuntime.ReleaseResourcesAndUnloadAppDomain(object state) + 0x35 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(object state) + 0x2f bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x53 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x59 bytes
[Appdomain Transition]
If nothing in your code is nulling out
_batchPrintProcessorthen a possible cause for the behavior you are seeing is that your ASP.NET application is being shut down (or restarted) by IIS. By default, Application Pools in IIS 7.5 are shut down every 20 minutes if there is no activity. You application will also be restarted by ASP.NET/IIS for a number of reasons, including changes to the bin directory, unhandled exceptions on spawned threads, etc.To check if this is the issue, just add some logging code to the
Application_StartandApplication_Endevents in your Global.asax.See also:
What causes an application pool in IIS to recycle?