c# - 最大定时器间隔

标签 c# .net

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

最佳答案

为此使用 System.Threading.Timer。有些构造函数采用 longuintTimeSpan 而不是 int截止时间。任何这些都可以让您设置 30 天的期限。

更新:这是最简单的方法:

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/

相关文章:

.net - 在 dot net app 中没有获得异常的行号

c# - 使用 Lambda 表达式进行字符串连接

.net - Azure 免费存储

.net - 将@section 放入@if .net mvc 3

.net - 您如何在 .Net 中设置单元测试项目?

c# - 绑定(bind)中继器中的所有数据

javascript - Ajax success() 可以处理两种类型的返回吗?

c# - AvalonEdit - 规则集跨度

c# - 在 LINQ 中查询所有嵌套的 XML 类型

c# - 使用 CodeDom 完成终结器?