Hi ,
Thanks for your reply.
But i want to implement functionality like allowing user to specify
start time and at that time only daily my task should run.
But timer is allowing me to set interval only.
What i did is i calcluated difference between current time and user
specified time and set that as a interval.
But my problem is for first time it is working properly but how will i
set timer interval to run it on next day at the same time.
If i am wrong please correct me.
Thanks.
kh wrote:
archana
i have a scheduling Windows Service working using System.Timers.Timer and it
is perfectly adequate for this task. how you use the timer depends on your
needs, but you can do something like this easily enough..
System.Timers.Timer timer;
public MyService()
{
InitializeComponent();
timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
protected override void OnStart(string[] args)
{
// set interval from config
try
{
this.timer.Interval =
Int32.Parse(System.Configuration.ConfigurationMana ger.AppSettings["TimerIntervalMinutes"]) * 60 * 1000;
}
catch
{
this.timer.Interval = 3600000;
}
timer.Start();
}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
timer.Stop();
try
{
// do something
}
finally
{
timer.Start();
}
}