【发布时间】:2016-08-30 07:48:07
【问题描述】:
我有以下作业计划每分钟运行一次,使用 hangfire 来尝试保持我的网站活跃,但它似乎仍然闲置?我刚刚检查了 hangfire 仪表板,看起来这项工作从未在周末运行过,大概是因为没有人访问该站点(注意它是一个 Intranet 应用程序)
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");
【问题讨论】:
标签: iis-7 httpwebrequest webclient application-pool hangfire