.NET 服务来监控网页变化 [英] .NET Service to monitor web page changes

查看:42
本文介绍了.NET 服务来监控网页变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个服务来监控网页的变化,即页面内容已经更新.我正在考虑实现这一目标的最佳方法,目前我正在考虑几个选项.请注意,可能有数百个页面需要监控,检查的时间间隔可能是几秒或几小时(可配置).

I want to create a service that will monitor changes to web pages i.e. the page content has been updated. I am trying to think of the best way to achieve this and at present I am considering a couple of options. Note that there could be hundreds of pages to monitor and the interval for checking could be seconds or hours (configurable).

  1. 为每个要监控的页面创建一个windows服务
  2. 创建一个 windows 服务,为每个页面生成一个线程以进行监控

现在,我担心哪些是最好的方法,以及这些是否是我尚未考虑的替代方法.我认为 1 将具有隔离每个监控任务的好处,但会以物理资源和创建/维护工作量方面的开销为代价.第二个会稍微复杂但更干净.显然它也会失去隔离,因为如果服务失败,那么所有的监控都会失败.

Now, I am concerned which of these is the best approach and whether these is an alternative I haven't considered. I thought 1 would have the benefit of isolating each monitoring task but would come at the expense of overhead in terms of physical resources and effort to create/maintain. The second would be slightly more complex but cleaner. Obviously it would also lose isolation in that if the service fails then all monitoring will fail.

推荐答案

我做了类似的事情,我通过使用持久化队列(SQL Server 表)来解决它,该队列将存储远程 Uri 以及时间间隔和日期时间最后一次运行.

I have done something similar and I solved it by having a persisted queue (a SQL Server table) that would store the remote Uri along with the interval and a DateTime for the last time it ran.

然后我可以通过选择那些具有 lastRun + interval < 的条目来获取我想要运行的所有条目.现在.

I can then get all entries that I want to run by selecting the ones that has lastRun + interval < now.

如果您的最小间隔在秒范围内,您可能希望使用 ThreadPool,以便您可以同时发出多个请求.(请记住相应地调整 app.config 中的 maxConnections 设置).

If your smallest interval are in the region of seconds, you probably want to use a ThreadPool, so that you can issue several request at the same time. (Remember to adjust the maxConnections setting in your app.config accordingly).

我会使用一个 Windows 服务(查看 TopShelf 项目),然后我会让 Quartz.Net 触发作业.使用 Quartz,您可以控制它是否必须等待先前的作业完成等.

I would use one Windows service (have a look at the TopShelf project for that) and I would then have Quartz.Net trigger the jobs. With Quartz, you can control whether it has to wait for previous jobs to finish etc.

这篇关于.NET 服务来监控网页变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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