Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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(); 
}
Posted
Updated 24-Aug-12 3:38am
v2
Comments
Legor 24-Aug-12 7:03am    
Please improve the question. How exactly are you sending the mails?
[no name] 24-Aug-12 7:08am    
Why on earth are you trying to do this in a web application?!? Either use a service or task scheduler for something like this. Your ASP session is probably timing out.
07405 24-Aug-12 7:13am    
i tried those but they doesn't work out for me
Anuja Pawar Indore 24-Aug-12 9:39am    
Added code block to the question

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.
 
Share this answer
 
Comments
07405 24-Aug-12 7:13am    
i tried those but they doesn't work out for me
Christian Graus 24-Aug-12 7:16am    
Well, instead of casting about at random, stick to what works and work out why you're not doing it properly. Ask questions about why you can't make a service work, instead of questions about doing things the wrong way.
07405 24-Aug-12 7:21am    
it worked out while we are checking it for few minutes in localhost. we are at final stage of our project. when we tested by hosting website for 24 hours we r not receiving mails.
Christian Graus 24-Aug-12 7:25am    
Well, then you need to work out why. Fact is, a service is the only viable way to do this, unless you create a stand alone console app that does your mailing and set up a scheduled task to run it. Services are better.
07405 24-Aug-12 7:30am    
ok can u suggest me how to write?
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
 
Share this answer
 
v2
Comments
Kuthuparakkal 24-Aug-12 7:53am    
Also you can initiate a thread from Global.asax, this separate thread always monitor and sends anything you like. void Application_Start(Object sender, EventArgs e) {
// Code that runs on application startup
// Your thread initiates here...

}
07405 24-Aug-12 7:57am    
i wrote it in global.asax

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;
}
it is not working for 24 hours
is there any other way to give 24 hours time
Kuthuparakkal 24-Aug-12 8:02am    
check this :
http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax
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
C#
if(DateTime.Now >= DateTimeSchedule){
   DateTimeSchedule = DateTime.Now.AddDays(1);
   //Do what was scheduled to happen

}


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.
 
Share this answer
 
v2
C#
public class TimerStarter
{
    private static Timer threadingTimer;
    public static void StartTimer()
    {

        if (null == threadingTimer)
        {
            threadingTimer = new Timer(new TimerCallback(DoActions), HttpContext.Current, 0, 8640000);
        }
    }
    private static void DoActions(object sender)
    {
        // all your mail calling methods here
    }
}


Then in application_start method in global.asax file.

void Application_Start(object sender, EventArgs e)
    {
         TimerStarter.StartTimer();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900