ASP.Net 应用程序的轮询策略?
我有一个 ASP.Net 应用程序,需要由另一台机器执行一些工作。 为此,我在两台机器都可见的队列上留下一条消息。 工作完成后,一条消息将留在第二个队列中。
我需要 ASP.Net 应用程序定期检查第二个队列以查看是否有任何任务已完成。
除了这样的循环,哪里是最好的地方呢? 全球.asax?
我记得在某处读过,你可以在一段时间间隔后调用一个函数。 那样合适吗?
I have an ASP.Net application that needs needs to have some work performed by another machine. To do this I am leaving a message on queue visible to both machines. When the work is done a message is left on second queue.
I need the ASP.Net application to check the second queue periodically to see if any of the tasks are complete.
Where is the best place to but such a loop? Global.asax?
I remember reading somewhere that you can get a function called after an interval. Would that be suitable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了在 ASP.NET 上实现定期任务,我发现了两种可接受的方法:
在这两种方式中,您都需要确保即使发生错误,您的线程也能继续工作。 您可以在 SessionStart 和 BeginRequest 中放置恢复代码来检查您的线程或缓存项是否存在,并在发生问题时更新它。
To achieve periodical tasks on asp.net, I've found two acceptable approaches:
In both ways, you need to make sure that your thread keeps working even if there happens an error. You may place a restore code in SessionStart and BeginRequest to check your thread or cache item is there, and renew it if something has happened to it.
我假设这是定期完成的,并且其他进程将项目放入队列中?
如果是这种情况,您可以在 Global.asax 中放入一些内容,在应用程序启动时创建一个单独的线程来简单地监视队列,您可以使用计时器让该线程休眠 X 秒,然后检查结果。
I assume that this is done on a regular basis, and that some other process puts the items on the queue?
If that is the case, you might put something in Global.asax that on application start creates a separate thread that simply monitors the queue, you could use a timer to have that thread sleep for X seconds, then check for results.