Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created windows service for auto mail triggering, Initially i set timer interval for every one minute, On elapsed event is triggered for every minute my mail part also working fine.

But i want the mail will trigger every day, for that i set timer interval is 1000*60*60*24, but the event not raised.

Below is the code:

protected override void OnStart(string[] args)
{
TraceService("start service");

//handle Elapsed event
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);

//This statement is used to set interval to 1 minute (= 60,000 milliseconds)
// timer = new System.Timers.Timer();
timer.Interval = 1000*60*60*24;

//enabling the timer
timer.Enabled = true;
timer.AutoReset = true;
timer.Start();


}






private void TraceService(string content)
{
//set up a filestream
FileStream fs = new FileStream(@"d:\ScheduledService.txt", FileMode.OpenOrCreate, FileAccess.Write);

//set up a streamwriter for adding text
StreamWriter sw = new StreamWriter(fs);

//find the end of the underlying filestream
sw.BaseStream.Seek(0, SeekOrigin.End);

//add the text
sw.WriteLine(content);

//add the text to the underlying filestream
sw.Flush();

//close the writer
sw.Close();
}
Posted
Comments
[no name] 28-Aug-13 10:34am    
Is your service still running after your OnStart method finishes? Have you checked the event logs? How do you know that the timer event does not fire?
Member 10237975 28-Aug-13 10:34am    
Please send replies.
Member 10237975 28-Aug-13 10:37am    
My service is running, but my log file shows no entries, i don't exactly whether the timer event is fired or not.
Member 10237975 28-Aug-13 10:38am    
timer event is..

private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService("Another entry at " + DateTime.Today);

// code............................
}

1 solution

Try using cron instead, here is an implementation in c# : Implementing a small Cron service in C#[^]
 
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