最大计时器间隔 [英] Maximum Timer interval

查看:52
本文介绍了最大计时器间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计时器的最大间隔为2,147,483,647.大约25天.但是根据我的要求,我需要计时器要等待30天.我该如何解决?请帮忙.

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.

推荐答案

为此使用 System.Threading.Timer .有些构造函数采用 long uint TimeSpan 而不是 int 来构造dueTime .这些中的任何一个都可以将您设置为30天.

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();
}

这篇关于最大计时器间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆