Maximum Timer interval

后端 未结 9 1272
心在旅途
心在旅途 2021-01-04 01:58

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.

相关标签:
9条回答
  • 2021-01-04 02:04

    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...

    0 讨论(0)
  • 2021-01-04 02:10

    This is the timer telling you your application is more properly implemented as a scheduled task.

    0 讨论(0)
  • 2021-01-04 02:15

    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.

    0 讨论(0)
  • 2021-01-04 02:19

    The Quartz.NET library is another option for running your code on a scheduled basis.

    0 讨论(0)
  • 2021-01-04 02:19

    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.

    0 讨论(0)
  • 2021-01-04 02:24

    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.

    0 讨论(0)
提交回复
热议问题