24小时计时器不工作 [英] 24 hours timer not working

查看:146
本文介绍了24小时计时器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......

我正在使用计时器来调用方法并发送每日邮件.但我给的计时器不起作用

myTimer.Interval = 86400000;
&
myTimer.Interval = 1000 * 60 * 60 * 24;

我尝试了这两个.如果我将其保留15分钟,则工作正常.


在此先感谢....
编辑添加的代码块,使用改进的解决方案来更新您的问题

Hi....

i am using a timer to invoke method and send daily mails. but its not working the timer which i had given is

myTimer.Interval = 86400000;
&
myTimer.Interval =1000*60*60*24;

i tried these two. if i kept it for 15 min it is working fine.


Thanks in advance....
Edit Added code block, use improve solution to update your question

void Application_Start(object sender, EventArgs e) { 
// Code that runs on application startup System.Timers.Timer myTimer = new System.Timers.Timer(); // Set the Interval to 5 seconds (5000 milliseconds). myTimer.Interval = 86400000; 
myTimer.AutoReset = true; 
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed); myTimer.Enabled = true; 
} 
public void myTimer_Elapsed(object source, System.Timers.ElapsedEventArgs e) {
 // use your mailer code
 ScheduleMail objScheduleMail = new ScheduleMail(); 
objScheduleMail.SendSurveyMailDaily();
objScheduleMail.SendSurveyMailWeekly(); 
objScheduleMail.SendSurveyMailMonthly(); 
objScheduleMail.SendCampaignMailDaily(); objScheduleMail.SendCampaignMailWeekly(); objScheduleMail.SendCampaignMailMonthly(); objScheduleMail.SendTemplatMailDaily(); objScheduleMail.SendTemplateMailsMonthly(); objScheduleMail.SendTemplateMailsWeekly(); objScheduleMail.EmailRemainders(); 
}

推荐答案

ASP.NET没有状态.即使您希望将计时器设置为24小时,也不要依赖应用程序"区域中的任何内容,编写一种可以为您发送邮件的Windows服务.
ASP.NET has no state. You should not rely on anything in the Application area even, if you want to set a timer for 24 hours, write a windows service that does your mailing for you.


通常有一些网站发送每周/每月的新闻通讯.如果您花一些时间来定制它,那一定会对您的网站有所帮助.不需要Web应用程序外部的调度程序/服务等...

看到这个:
http://www.stardeveloper.com/articles/display.html?article=2008100201& page = 1 [ ^ ]

过去我提到过一个美丽的项目,叫做"TheBeerHouse".而且是很棒的东西.它具有民意测验,投票,文章,新闻通讯,管理员.也是ASP.Net成员资格服务的良好教程.到目前为止遇到了很棒的东西.
http://thebeerhouse.codeplex.com/ [ ^ ]

谢谢,

Kuthuparakkal
There are sites usually send Newsletters every week/month. If you take sometime to customize this, will be a sure hit for your website. Ther''s no need of scheduler/service etc external to web app...

See this :
http://www.stardeveloper.com/articles/display.html?article=2008100201&page=1[^]

I refered a beautiful project in the past, it''s called "TheBeerHouse". And is a great stuff. It has Polls, Voting, Articles, NewsLetter, Admin. Also good tutorial for ASP.Net Membership services. Great stuff so far met.
http://thebeerhouse.codeplex.com/[^]

Thanks,

Kuthuparakkal


哦,哥们不要那样做

间隔计时器应为用户,但不应用于等待一定时间.

而是创建时间表.

对于您的情况,可以说您希望在初始化后的第一天使某事发生.
加上当前的Date DateTime.Now.AddDays(1);

那么您可以使用计时器每隔1分钟检查一次,因此每隔60000毫秒检查一次
Oh buddy dont do that

Interval timers should be user but they should not be used to wait until a certain amount of time has elapsed.

Rather create schedules.

In your case lets say you wish to make sometthign happen 1 day after it has been initialised.
Thake the current Date DateTime.Now.AddDays(1);

then you use your timer that checks every say 1 minute so every 60000 milisecond interval
if(DateTime.Now >= DateTimeSchedule){
   DateTimeSchedule = DateTime.Now.AddDays(1);
   //Do what was scheduled to happen

}



这将确保PC掉线后您的计时器不会再次从顶部开始

PS作为警告使用Windows服务,这是因为ASP.NET进程每奇数分钟就会被回收一次,这意味着即使您的计时器正在运行,asp.net也会决定回收该进程.表示您的计时器将完全关闭.


在完全没有办法解决这个问题之前,我没有办法通过使用HTTP Web客户端在网站回收后重新激活该网站来解决此问题,但是它变得非常混乱.



This will ensure that went the PC goes down your timer wont start from the top again

PS as a warning use windows services for this, the reason is that ASP.NET processes gets recycled every odd minutes meaning that even though your timer is running asp.net will decide to recycle the process. meaning your timer will completely shut down.


I got completely burnt on this before there is a way to get around this by using a HTTP web client to reactivate the website when it gets recycled but it gets very messy.


这篇关于24小时计时器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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