Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.