定时器的最大间隔为2,147,483,647。大约25天。但在我的要求中,我需要计时器等待 30 天。我该如何解决?请帮忙。
最佳答案
为此使用 System.Threading.Timer
。有些构造函数采用 long
、uint
或 TimeSpan
而不是 的
。任何这些都可以让您设置 30 天的期限。int
截止时间
更新:这是最简单的方法:
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();
}
关于c# - 最大定时器间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1624789/