C#的ping一个网站? (保持活动的服务) [英] c# ping a website? (keep-alive service)

查看:198
本文介绍了C#的ping一个网站? (保持活动的服务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在C#的方式能够ping通每15分钟一个URL并得到响应从服务器返回的?

is there a way in c# to be able to ping a url every 15 minutes and get a response back from the server?

我想试试,看看.NET可以被用来建立一个简单的工具有asp.net网站调用重新构建,使应用程序启动时第一个用户不会产生负荷损失。

i want to try to see if .net can be used to build a simple tool to have asp.net websites invoke a re-build so that the first user doesn't incur the load penalty when the application is started.

或者如果任何人有完成相同的目标的另一种方法...
想法?提示?想法?

or if anyone has an alternative method of accomplishing the same goal... thoughts? tips? ideas?

推荐答案

通常推着释放自己上载的网站只是为了测试后应该访问(确保没有轰炸)的人。但是,如果你正在寻找一个编程方法, Web客户端可能会有所帮助...

Typically the person pushing a release should visit after they've uploaded the site just for test sake (make sure nothing bombed out). But if you're looking for a programmatic approach, WebClient may be helpful...

using (WebClient client = new WebClient())
{
  client.DownloadString("http://wwww.sitename.com/");
}

然后让一个exe和使用Windows计划程序来运行它。甚至可以把它放进一个WINSERVICE和报告状态到日志文件。

Then make it an exe and use the windows scheduler to run it. Could even put this in a WinService and report status to log files.

更新:

它看起来像VS2012现在后发布打开页面,使这些推该网站是第一要求。

It looks like VS2012 now opens the page after a publish, making those pushing the site be the first-request.

另外,如果你发现你不必访问它经常可能要到看重新配置IIS /程序池,并改变周期时间较长的东西(如在问题中提到每15分钟)。 IIS本身节约一点用都没有的资源,因此,如果一个网站没有被在一段时间查询它实际上将释放内存为其他应用程序使用。

Also, if you find you're having to visit it that frequently (every 15 minutes as mentioned in question) you may want to look in to reconfiguring the IIS/AppPool and change the cycle time to something longer. IIS natively conserves resources that are not used, and so if a site hasn't been queried in a while it will actually release the memory for another application to use.

这篇关于C#的ping一个网站? (保持活动的服务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆