惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
V
V2EX
爱范儿
爱范儿
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
罗磊的独立博客
A
About on SuperTechFans
MyScale Blog
MyScale Blog
S
Security @ Cisco Blogs
博客园 - 聂微东
Simon Willison's Weblog
Simon Willison's Weblog
Cyberwarzone
Cyberwarzone
云风的 BLOG
云风的 BLOG
U
Unit 42
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Security Latest
Security Latest
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
美团技术团队
S
Securelist
P
Privacy International News Feed
T
Tenable Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
Google Online Security Blog
Google Online Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
W
WeLiveSecurity
A
Arctic Wolf
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
V2EX - 技术
V2EX - 技术

博客园 - asheng

JavaScript UI选型及Jquery EasyUI使用经验谈 云计算风险识别 五年之痒 敏捷软件开发 嫁给程序员吧!!! Cute Editor for .NET v6.4 Java与.NET的WebServices相互调用 用户体验5大要素 【转】LINQ To XML 入门(3) 【转】LINQ To XML 入门(2) 【转】LINQ To XML 入门(1) 学写Windows Service 微软发布ASP.NET MVC框架1.0正式版 CSS分类编写方法 JS中错误处理(2) JS中错误处理(1) Log4Net OWC画图表 - asheng - 博客园 好员工为什么会变坏
Web定时任务
asheng · 2009-02-11 · via 博客园 - asheng

想在Web中定时 处理某些任务吧?
可以在Global.asax 中定义,直接上例子:

<script runat="server">
    
void Application_Start(object sender, EventArgs e) 
    {
       
       
// 应用程序启动时
       System.Timers.Timer timer = new System.Timers.Timer();
       DateTime sTime 
= DateTime.Now;
       
int sHour = sTime.Hour;
       
int sMin = sTime.Minute;
       
int sSecond = sTime.Second;
       
int sHourInterval = 15 - sHour;
       
int sSecondInterval = sHourInterval * 60 * 60 * 1000;
       
//timer.Interval = 1000*5;//5秒发送一次
       timer.Interval = sSecondInterval;
       
//timer.AutoReset;
       timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
       timer.Enabled 
= true;

    }

void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        
string s_from = "fengsheng@xxx.com";
        
string s_to = "fengsheng@xxx.com";
        
string pwd = "1234567";
        
string s_body = "test";
        
string s_smtp = "mail.xxx.com";
        
int i = s_from.IndexOf("@");
        
string s_subjetc = "test";
        
string username = s_from.Substring(0, i);
        System.Net.Mail.MailAddress from 
= new System.Net.Mail.MailAddress(s_from);
        System.Net.Mail.MailAddress to 
= new System.Net.Mail.MailAddress(s_to);
        System.Net.Mail.MailMessage mailobj 
= new System.Net.Mail.MailMessage(from, to);
        mailobj.Subject 
= s_subjetc;
        mailobj.Body 
= s_body;

        mailobj.IsBodyHtml 

= true;
        mailobj.BodyEncoding 
= System.Text.Encoding.GetEncoding("GB2312");
        mailobj.Priority 
= System.Net.Mail.MailPriority.High;
        System.Net.Mail.SmtpClient smtp 
= new System.Net.Mail.SmtpClient();
        smtp.Host 
= s_smtp;
        smtp.UseDefaultCredentials 
= true;
        smtp.Credentials 
= new System.Net.NetworkCredential(username, pwd);
        smtp.Send(mailobj);
    }
</script>

上面 是一个定时发邮件的小例子,一举两得,还给大家了一个发邮件的例子 ,呵呵
建议最好是把需要启动的事项 做成 web Service 这样 应用范围会更广~

//****************************************
  by: Amen cnblogs博客  转载请注明出处
//****************************************