在托管 Web 服务器中安排作业 [英] Schedule a job in hosted web server

查看:31
本文介绍了在托管 Web 服务器中安排作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能给我一种使用 .NET 技术实现日常工作的最佳方法吗?我有一个 asp.net 应用程序,sqlserver 数据库托管在共享主机中,在我的实例中为 GODaddy.我的应用程序用于添加/更改数据库中的数据,此时该数据库的性能相当不错.我收到了一项新要求,即根据存储在数据库中的一些数据标准,每天发送一些电子邮件警报.

Can some one give me a best way to implement a daily job with .NET technology. I have an asp.net application with the sqlserver database hosted in shared hosting, GODaddy in my instance. My application is used to add / change the data in the database which is performing quite fairly at this time. I got a new requirement to send some email alerts daily based on some data criteria that were stored in the database.

最初我想编写一个 Windows 服务,但 Godaddy 不允许访问除托管应用程序之外的数据库.有人知道每天凌晨 1:00 发送警报吗?

Initially I thought to write a windows service, but godaddy is not allowing to access the database other than its hosted applications. Does someone has any idea to send alerts daily at 1:00AM?

提前致谢

推荐答案

参见 EasyASP.NET 中的后台任务 作者:Jeff Atwood.

See Easy Background Tasks in ASP.NET by Jeff Atwood.

从链接复制/粘贴:

private static CacheItemRemovedCallback OnCacheRemove = null;

protected void Application_Start(object sender, EventArgs e)
{
    AddTask("DoStuff", 60);
}

private void AddTask(string name, int seconds)
{
    OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
    HttpRuntime.Cache.Insert(name, seconds, null,
        DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration,
        CacheItemPriority.NotRemovable, OnCacheRemove);
}

public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
{
    // do stuff here if it matches our taskname, like WebRequest
    // re-add our task so it recurs
    AddTask(k, Convert.ToInt32(v));
}

这篇关于在托管 Web 服务器中安排作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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