Darey
Darey

Reputation: 497

Calling a method or action during a particular time

I have an operation that needs to be run once every day at 12 AM. I have implemented the same by using Condition check constraints matching DateTime.Now.Hour == someValue; However, I don't want the while loop to be running n number of times for just one time operation. I have made the thread to sleep But still I ain't satisfied with the solution. Trying out with Timers will also wont work out. Do we have any concepts called Clock or Time coupled with events which invokes a particular action on a respective time. Please clarify.

Upvotes: 0

Views: 50

Answers (1)

Raja Nadar
Raja Nadar

Reputation: 9489

some options:

  1. Windows NT Scheduled tasks of simple EXEs do the job in many scenarios where the functionality and time-logic are separated.
  2. Windows Services with timers is another option. Not sure why timers don't work for you. Note, you need to have 2 inputs to the service.. RunImmediatelyOnStartup and AbsoluteTimeOfNextRun.. based on that you can avoid startup-time mismatch issues.
  3. Normal EXEs with timers is another option.
  4. Normal EXEs with Sleep is another option.

in short, timers help avoid constant polling.. and Sleep allows you to regulate your polls. better than an insane while loop, which might affect CPU.

Upvotes: 1

Related Questions