0

I wrote a windows service on Visual Studio. It's a bot actually based on Selenium. It needs to log in to my account on a website every 8 hours. The problem is it waits for the time to be passed (for 8 hours) and then starts getting executed. I want it to get started once I start the windows service and then keep running every 8 hours. I used windows service template on Visual Studio.

protected override void OnStart(string[] args)
    {
        WriteToFile("Service is started at " + DateTime.Now);
        timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
        timer.Interval = 28800000;
        timer.Enabled = true;


    }
Earlingh
  • 23
  • 4
  • 1
    You can write a simple program that will do the job one time and exit afterwards. Start it with the windows built in scheduler every 8 hours. – Sir Rufo Aug 13 '23 at 11:24
  • @SirRufo I'm doing this for someone else on a different computer. He just needs to type a single line of command code to get this service ran on his computer. My code works fine every 8 hours. I just need it to run once I start it. – Earlingh Aug 13 '23 at 11:43

0 Answers0