Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum Timer interval

Tags:

c#

.net

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.

like image 226
hovkar Avatar asked Oct 26 '09 13:10

hovkar


People also ask

What is timer interval in C#?

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.

What is interval timer called?

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.

What is timer interval in VB net?

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

What are the functions of interval timer?

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.


2 Answers

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();
}
like image 196
MusiGenesis Avatar answered Oct 01 '22 19:10

MusiGenesis


int days = 30;

Create a timer for a period one day.

Decrement days each time the timer fires.

like image 30
Bob Kaufman Avatar answered Oct 01 '22 19:10

Bob Kaufman