The maximum interval of timer is 2,147,483,647. it\'s about 25 days. But in my requirements I need that the timer will wait 30 days. How can I resolve it? Please help.
Set a datetime variable to the datetime when you want to execute whatever it is... Then just have the timer check every minute, (or whatever your level of required accuracy is) to see if that datetime has past...
This is the timer telling you your application is more properly implemented as a scheduled task.
You can always have the timer wait a shorter amount of time, like one day and each time the timer fires increment a counter and check the current value of the counter. If the value is 30 then execute the code that is supposed to run once every 30 days.
A better idea is to set the value some where in an external file so that if the program ever unexpectedly quits, you can resume where you left off. Ideally you'd probably want to put the next run date in the file, so that if the program is off for multiple days you can resume and have it fire on the correct date without having to worry about when the last time it ran. So something like
NextRunDate = 10/10/2009 4:40 PM
When the program runs it sets the date ahead another 30 days.
The Quartz.NET library is another option for running your code on a scheduled basis.
The timer constructor will take a TimeSpan which is int64 ticks surely that's over 25 days?
Have you also considered that the system may not stay up for 30 days?
Just looked it up, it's 10,675,199 days.
I highly suggested using the Windows Scheduled Task feature, especially if this is intended to run something on the same day each month, as months vary between 28 and 31 days.