ASP.NET中调度任务的方法(无需编写Windows调度程序)
我喜欢共享主机,他们不允许我使用 Windows 调度程序...那么在 ASP.NET 中实现计划任务即(定时邮件)的方法是什么...我刚刚看到 后台进程...可靠吗?或者执行计划任务的任何其他方式...
然后我找到 quartz.net 但我找不到一个将quartz.net嵌入到asp.net中的简单示例(无需安装Quartz.Net服务器作为独立的Windows服务)...关于quartz.net的任何建议...
I am into shared hosting and they do not allow me to use windows scheduler... So what are the ways of achieving scheduled tasks ie(timed mail) in asp.net... I just saw background process by Jeff Atwood blog... Is it relaible? Or any other ways of doing scheduled tasks...
Then i found quartz.net but i can't find a simple example that embeds quartz.net into an asp.net(without installing a Quartz.Net server as a standalone windows service)... Any suggestion on quartz.net...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以简单地编写一个 ASP.Net 页面来执行您的任务,例如发送邮件。然后使用 SetCronJob 等在线调度服务按计划调用服务器上页面的 URL。
这种非常简单的方法的缺点是您依赖于外部服务。
You could simply write an ASP.Net page that performs your task, e.g. sending the mails. Then use an online scheduling service like SetCronJob to call the URL of the page on your server on a schedule.
The downside of this very simple approach is that you are dependent on an external service.
我正在调查 Microsoft.Web .管理程序集 Schedule Class 实现相同的功能,但似乎该类只能用于安排 IIS 工作进程重新启动,这里是 创建应用程序池并设置定期重启的示例。
因此,唯一的方法是重新启动 ASP.NET 应用程序,然后在 Application_Start 中执行计划的工作。 但这是丑陋的黑客而不是解决方案,所以最后我最终为我们自己开发的备份窗口服务添加了调度功能,该服务已经在网络服务器上运行,所以IMO Quartz.net是最适合您的解决方案。也许你可以说服你的网络提供商安装 Quartz.net 所有其他解决方案似乎都是一个黑客,会给你带来或多或少的问题。
I was investigating Microsoft.Web.Administration assembly Schedule Class to achieve same thing but it seems that class can be used only to schedule IIS worker process restart, here is the example of creating app pools and setting periodical restart.
So only way was to schedule with this was ASP.NET app restart and then in Application_Start do the scheduled work. But that is ugly hack not solution, so at the end I ended up adding scheduling capabilities to our homegrown backup windows service that was allready running on web server, so IMO Quartz.net is the best solution for you. Maybe you could convince your web provider to install Quartz.net all other solutions seems like a hack that will give you more or less problems.
.NET 计划计时器
或
数据绑定时间表控件
.NET Scheduled Timer
or
Databound Schedule controls
您可以从此中获取想法并放置您的任务在KeepAlive方法中。希望!它有帮助。
You can take idea from this and put your task in KeepAlive method. Hope! It helps.
不久前我也遇到了同样的问题,并且由于没有使用第三方服务,所以没有很好的解决方法。
也就是说,我使用了过期时间为 24 小时的 .NET 应用程序缓存对象。
然后在我的基页面类中,每次发出页面请求时,我都会检查该变量是否存在,如果存在,我就会运行该任务。这样做的缺点是,您依赖于向您的应用程序发出的页面请求。
最后,我看到的另一种方法是在缓存到期时设置回调(CacheItemRemovedCallback 方法),然后链接该方法以将新项目插入到缓存中,该缓存也有回调,因此循环重复。
I had this very same problem not long ago, and short of using a third party service, there are no great ways around it.
That said, I used the .NET Application Cache object with an expiry time of 24 hours.
Then in my base page class, everytime a page request was made, I checked for the existing of that variable, and if existing, I ran the task. The downside of this is that then you are reliant on there being page requests made to your application.
Lastly, another way I have seen this done, is to set a callback on the cache expiry (CacheItemRemovedCallback method) and then chain that method to insert a new item into the cache which also has a callback and so the cycle repeats.
System.Timers.Timer - http://msdn.microsoft。 com/en-us/library/system.timers.timer.aspx
在你的 global.asax 中启动它
System.Timers.Timer - http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
start it up in your global.asax