ASP.Net应用程序空闲超时和应用程序池回收

时间:2016-08-30 07:48:07

标签: iis-7 httpwebrequest webclient application-pool hangfire

我有以下工作,每分钟使用hangfire运行以尝试保持我的网站活着,但它似乎仍然闲置?我刚刚查看了hangfire仪表板,看起来这个工作从未在周末推出过,因为没有人访问过网站(注意它是一个内部网应用程序)

 try
 {
    var url = "http://xyz.domain.com/myapp"
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.Timeout = 6000;
    request.AllowAutoRedirect = false; 
    request.Method = "HEAD";

    using (var response = request.GetResponse())
    {
               // TO DO
    }
 }
 catch (Exception ex)
 {
     logger.Error(ex, "Error in KeepAlive job");
 } 

使用webclient会更可靠,还是与使用HttpWebRequest相同 - 如下所示:

WebClient webClient = new WebClient();
Stream stream = webClient.OpenRead("http://xyz.domain.com/myapp"); 

1 个答案:

答案 0 :(得分:1)

默认情况下,在第一个用户访问您的网站之前,不会启动Web应用程序中的Hangfire Server实例。更重要的是,有些事件会在一段时间后关闭您的Web应用程序(我在谈论Idle Timeout和不同的应用程序池回收事件)。在这些情况下,您的重复任务和延迟的工作将不会排队,并且不会处理排队的工作。

这对于较小的网站尤其如此,因为可能存在长时间的用户不活动。但是,如果您正在运行关键作业,则应确保始终运行Hangfire Server实例以保证及时后台作业处理。

http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html