Timer.Interval is an Integer, so I can't set it to more than 2^32 milliseconds I think. How would you work this around? I'd like to set some event to happen after 3 months for example. I tried to code this but I couldn't make it work... Thank you.
Printable View
Timer.Interval is an Integer, so I can't set it to more than 2^32 milliseconds I think. How would you work this around? I'd like to set some event to happen after 3 months for example. I tried to code this but I couldn't make it work... Thank you.
I assume the 3 month limit would begin when the program was originally turned on. If that is the case, you write a date 3 months from then to a database or flat file, for example. Then when the program is started up, or some other event is triggered, check the current date against the date you saved out. If it is past the 3 month limit, do your action.
Use multiple timers. For instance, if maximum timer could only do 24 hours, and you want to trigger something in 3 days(72 hrs), then create three timers that have 24 hour intervals. Start the first timer, then when 24 hour is up, make that first timer run a code, ie. timer2.enabled = true, then that second timer starts, and when 24 hour is up, make it start timer3 with timer3.enabled = true, then when timer3 is up, then make it run whatever function you want.
mndepaul: Your solution works if you assume that my computer will never be turned on for more that 1 month continuously. But you did give me an idea. I will have the timer disabled by default and check in a separate thread if I have any alarm in the next week. If I do, I enable the timer and set the interval.
benmartin101: what if I want to set an alarm after 3 years? :)
The Timer Interval specifies how many milliseconds between Tick events. That doesn't mean that your Timer can't Tick an indefinite number of times. Save the date and time that you want the alarm to go off and then check whether the current time is past that time at each Tick. You would set the Interval as large as your required precision allows. if you just have to make sure the alrm goes off on the right day then set your Interval to 24 hours. If you need it in the right hour then set your Interval to 1 hour. The largest possible Interval is about 25 days if I remember correctly. Whatever Integer.MaxValue milliseconds equates to in days.