private static void RunTaskOnNewThread(object threadSleepTask) { if (threadSleepTask == null) { return; } AppKeepAliveTask task = (AppKeepAliveTask)threadSleepTask; log.Info("deserialized AppKeepAliveTask task"); // give a little time to make sure the taskqueue was updated after spawning the thread Thread.Sleep(10000); // 10 seconds task.RunTask(); log.Info("started AppKeepAliveTask task"); }
//public static void RegisterRoutes(RouteCollection routes) //{ // routes.Clear(); // RoutingHandler.Configure(routes); //} //#if!NET35 // private void SetupMonitoring() // { // if (appDomainMonitoringEnabled) // { // AppDomain.MonitoringIsEnabled = true; // } // if (firstChanceExceptionMonitoringEnabled) // { // AppDomain.CurrentDomain.FirstChanceException += (object source, FirstChanceExceptionEventArgs e) => // { // if (HttpContext.Current == null)// If no context available, ignore it // return; // if (HttpContext.Current.Items[RequestExceptionKey] == null) // HttpContext.Current.Items[RequestExceptionKey] = new RequestException { Exceptions = new List<Exception>() }; // (HttpContext.Current.Items[RequestExceptionKey] as RequestException).Exceptions.Add(e.Exception); // }; // } // } // private void CaptureMonitoringData() // { // if (!firstChanceExceptionMonitoringEnabled) { return; } // if (Context.Items[RequestExceptionKey] != null) // { // //Only add the request if atleast one exception is raised // var reqExc = Context.Items[RequestExceptionKey] as RequestException; // reqExc.Url = Request.Url.AbsoluteUri; // Application.Lock(); // if (Application["AllExc"] == null) // Application["AllExc"] = new List<RequestException>(); // (Application["AllExc"] as List<RequestException>).Add(reqExc); // Application.UnLock(); // } // } //#endif private void StartOrResumeTasks() { // NOTE: In IIS 7 using integrated mode, HttpContext.Current will always be null in Application_Start // http://weblogs.asp.net/jgaylord/archive/2008/09/04/iis7-integrated-mode-and-global-asax.aspx if (WebConfigSettings.UseAppKeepAlive) { AppKeepAliveTask keepAlive; try { try { if ((HttpContext.Current != null) && (HttpContext.Current.Request != null)) { keepAlive = new AppKeepAliveTask(); keepAlive.UrlToRequest = WebUtils.GetSiteRoot(); keepAlive.MaxRunTimeMinutes = WebConfigSettings.AppKeepAliveMaxRunTimeMinutes; keepAlive.MinutesToSleep = WebConfigSettings.AppKeepAliveSleepMinutes; keepAlive.QueueTask(); } } catch (HttpException) { //this error will be thrown when using IIS 7 Integrated pipeline mode //since we have no context.Request to get the site root, in IIS 7 Integrated pipeline mode //we need to use an additional config setting to get the url to request for keep alive if (WebConfigSettings.AppKeepAliveUrl.Length > 0) { keepAlive = new AppKeepAliveTask(); keepAlive.UrlToRequest = WebConfigSettings.AppKeepAliveUrl; keepAlive.MaxRunTimeMinutes = WebConfigSettings.AppKeepAliveMaxRunTimeMinutes; keepAlive.MinutesToSleep = WebConfigSettings.AppKeepAliveSleepMinutes; keepAlive.QueueTask(); } } } catch (Exception ex) { // if a new installation the table will not exist yet so just log and swallow log.Error(ex); } } WebTaskManager.StartOrResumeTasks(true); }
//public static void RegisterRoutes(RouteCollection routes) //{ // routes.Clear(); // RoutingHandler.Configure(routes); //} //#if!NET35 // private void SetupMonitoring() // { // if (appDomainMonitoringEnabled) // { // AppDomain.MonitoringIsEnabled = true; // } // if (firstChanceExceptionMonitoringEnabled) // { // AppDomain.CurrentDomain.FirstChanceException += (object source, FirstChanceExceptionEventArgs e) => // { // if (HttpContext.Current == null)// If no context available, ignore it // return; // if (HttpContext.Current.Items[RequestExceptionKey] == null) // HttpContext.Current.Items[RequestExceptionKey] = new RequestException { Exceptions = new List<Exception>() }; // (HttpContext.Current.Items[RequestExceptionKey] as RequestException).Exceptions.Add(e.Exception); // }; // } // } // private void CaptureMonitoringData() // { // if (!firstChanceExceptionMonitoringEnabled) { return; } // if (Context.Items[RequestExceptionKey] != null) // { // //Only add the request if atleast one exception is raised // var reqExc = Context.Items[RequestExceptionKey] as RequestException; // reqExc.Url = Request.Url.AbsoluteUri; // Application.Lock(); // if (Application["AllExc"] == null) // Application["AllExc"] = new List<RequestException>(); // (Application["AllExc"] as List<RequestException>).Add(reqExc); // Application.UnLock(); // } // } //#endif private void StartOrResumeTasks() { // NOTE: In IIS 7 using integrated mode, HttpContext.Current will always be null in Application_Start // http://weblogs.asp.net/jgaylord/archive/2008/09/04/iis7-integrated-mode-and-global-asax.aspx if (WebConfigSettings.UseAppKeepAlive) { AppKeepAliveTask keepAlive; try { try { if ((HttpContext.Current != null) && (HttpContext.Current.Request != null)) { keepAlive = new AppKeepAliveTask(); keepAlive.UrlToRequest = WebUtils.GetSiteRoot(); keepAlive.MaxRunTimeMinutes = WebConfigSettings.AppKeepAliveMaxRunTimeMinutes; keepAlive.MinutesToSleep = WebConfigSettings.AppKeepAliveSleepMinutes; keepAlive.QueueTask(); } } catch (HttpException) { //this error will be thrown when using IIS 7 Integrated pipeline mode //since we have no context.Request to get the site root, in IIS 7 Integrated pipeline mode //we need to use an additional config setting to get the url to request for keep alive if (WebConfigSettings.AppKeepAliveUrl.Length > 0) { keepAlive = new AppKeepAliveTask(); keepAlive.UrlToRequest = WebConfigSettings.AppKeepAliveUrl; keepAlive.MaxRunTimeMinutes = WebConfigSettings.AppKeepAliveMaxRunTimeMinutes; keepAlive.MinutesToSleep = WebConfigSettings.AppKeepAliveSleepMinutes; keepAlive.QueueTask(); } } } catch (Exception ex) { // if a new installation the table will not exist yet so just log and swallow log.Error(ex); } } WebTaskManager.StartOrResumeTasks(true); }