如何生成在C#中的特定时间报警? [英] How do I generate an alert at a specific time in C#?

查看:138
本文介绍了如何生成在C#中的特定时间报警?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能在特定时间的事件?例如,假设我要产生在上午8点,通知我的8:00 AM警报(或在任何给定的时间告诉我的当前时间的事件)。

How can i generate an event at a specific time? For example, say I want to generate an alert at 8:00 AM that informs me its 8:00 AM (or an event that informs me of the current time at any given time).

推荐答案

使用的<一个href=\"http://msdn.microsoft.com/en-us/library/system.threading.timer.timer.aspx\">System.Threading.Timer类:

var dt = ... // next 8:00 AM from now
var timer = new Timer(callback, null, dt - DateTime.Now, TimeSpan.FromHours(24));

回调委托将被调用,下一次是上午8:00,此后每隔24小时。

The callback delegate will be called the next time it's 8:00 AM and every 24 hours thereafter.

请参阅这太问题如何计算下一8:00 AM发生。

See this SO question how to calculate the next 8:00 AM occurrence.

这篇关于如何生成在C#中的特定时间报警?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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