Have windows service run specific day & time weekly - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Have windows service run specific day & time weekly

bbcompent1bbcompent1 Posts: 3Member
Hello experts, I'm looking for help here so bear with me. Due to circumstances I have no control over, I cannot use Windows Task Scheduler for this. I have to use a windows service with a System.Timers.Timer call. What I'd like to do is have the service run on a specific day of the week at a specific time that I specify in my app.config file. Here's the code I have so far and I suspect I'm going to need a try/catch block.

[code]
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
_timer = new System.Timers.Timer();
_timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
_timer.Enabled = true;
_timer.Interval = ReadTime;
_timer.Start();
}

protected override void OnStop()
{

}

void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
_lastRun = DateTime.Now;
_timer.Stop();
_thread = new Thread(new ThreadStart(APFImporter));
_thread.Name = "DoImport";
_thread.Start();
_timer.Start();
}

[/code]
Sign In or Register to comment.