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.
C# Timer is used to implement a timer in C#. The Timer class in C# represents a Timer control that executes a code block at a specified interval of time repeatedly. For example, backing up a folder every 10 minutes, or writing to a log file every second.
Real-time applications often schedule actions using interval timers. Interval timers can be either of two types: a one-shot type or a periodic type. A one-shot is an armed timer that is set to an expiration time relative to either current time or an absolute time.
The default interval is 100 milliseconds, but the range of possible values is 1 to 2,147,483,647. A timer is typically used in a VB.Net program by creating an event handler for its Tick event (the event handler contains code that will be executed when a Tick event occurs).
The INTERVAL-TIMER function returns the number of seconds starting from an arbitrary point in time. Typically, you will want to use the function twice or more in order to take differences between the return values in order to time something.
Use a System.Threading.Timer
for this. There are constructors that take a long
, a uint
or a TimeSpan
instead of an int
for the dueTime
. Any of these will let you set a period of 30 days.
Update: this is the easiest way to do it:
System.Threading.Timer _timer;
public void Start30DayTimer()
{
TimeSpan span = new TimeSpan(30, 0, 0, 0);
TimeSpan disablePeriodic = new TimeSpan(0, 0, 0, 0, -1);
_timer = new System.Threading.Timer(timer_TimerCallback, null,
span, disablePeriodic);
}
public void timer_TimerCallback(object state)
{
// do whatever needs to be done after 30 days
_timer.Dispose();
}
int days = 30;
Create a timer for a period one day.
Decrement days
each time the timer fires.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With