C# - Alternative to System.Time.Timer, to call a function at a specific time.

Posted by Fábio Antunes on Stack Overflow See other posts from Stack Overflow or by Fábio Antunes
Published on 2010-04-23T14:57:14Z Indexed on 2010/04/23 15:03 UTC
Read the original article Hit count: 449

Filed under:
|
|
|

Hello everybody.

I want to call a specific function on my C# application at a specific time. At first i thought about using a Timer (System.Time.Timer), but that soon became impossible to use. Why?

Simple. The Timer Class requires a Interval in milliseconds, but considering that i might want the function to be executed, lets says in a week that would mean:

  • 7 Days = 168 hours;
  • 168 Hours = 10,080 minutes;
  • 10,080 Minutes = 6,048,000 seconds;
  • 6,048,000 Seconds = 6,048,000,000 milliseconds;
  • So the Interval would be 6,048,000,000;

Now lets remember that the Interval accepted data type is int, and as we know int range goes from -2,147,483,648 to 2,147,483,647.

That makes Timer useless in this case once we cannot set a Interval bigger that 2,147,483,647 milliseconds.


So i need a solution where i could specify when the function should be called. Something like this:

solution.ExecuteAt = "30-04-2010 15:10:00";
solution.Function = "functionName";
solution.Start();

So when the System Time would reach "30-04-2010 15:10:00" the function would be executed in the application.

How can this problem be solved?

Thanks just by taking the time to read my question. But if you could provide me with some help i would be most grateful.


Additional Info: What these functions will do?

  • Getting climate information and based on that info:
    • Starting / Shutting down other Applications (most of them Console Based);
    • Sending custom Commands to those Console Applications;
    • Power down, Rebooting, Sleep, Hibernate the computer;
    • And if possible schedule the BIOS to Power Up the Computer;

© Stack Overflow or respective owner

Related posts about c#

Related posts about scheduled-tasks