/* * Try batching the directory if not done yet. */ private static bool BatchCompileDirectory(HttpContext context, string baseVirtualDir) { // Don't do it if batching is disabled if (!CompilationConfiguration.IsBatchingEnabled(context)) { return(false); } if (AlreadyBatched(baseVirtualDir)) { return(false); } Debug.Trace("PreservedAssemblyEntry", "Need to batch compile " + baseVirtualDir); // If we're already in a batch compilation tread, no need to start another one if (BackgroundBatchCompiler.IsBatchCompilationThread()) { Debug.Trace("PreservedAssemblyEntry", "Already in batch compilation thread. No need to start a new one."); CodeDomBatchManager.BatchCompile(baseVirtualDir, context); return(true); } // Notify HttpRuntime so that it might need to abort compilation on shutdown HttpRuntime.NotifyThatSomeBatchCompilationStarted(); ManualResetEvent batchEvent = new ManualResetEvent(false); // Pass it a Clone of the context, since it's not thread safe. Mostly, this is important // for the ConfigPath (ASURT 82744) BackgroundBatchCompiler bbc = new BackgroundBatchCompiler(context.Clone(), baseVirtualDir, batchEvent); // Start the batch processing try { ThreadPool.QueueUserWorkItem(bbc.BatchCallback); } catch { return(false); } // Register for BeforeDoneWithSession event context.BeforeDoneWithSession += new EventHandler(bbc.BeforeDoneWithSessionHandler); // Wait a certain time for it to complete int timeout = 1000 * CompilationConfiguration.GetBatchTimeout(context); Debug.Trace("PreservedAssemblyEntry", "Waiting for " + timeout + " ms"); if (batchEvent.WaitOne(timeout, false)) { Debug.Trace("PreservedAssemblyEntry", "The background thread is done for " + baseVirtualDir + " (Success=" + bbc.Success + ")"); return(bbc.Success); } // It didn't have time to complete. Let it run in the background. Debug.Trace("PreservedAssemblyEntry", "The background thread is still going for " + baseVirtualDir); // Add it to the list of background compilations, in case it needs to be aborted AddBackgroundBatchCompilation(bbc); bbc.WasAddedToBackgroundThreadsList = true; return(false); }