如何实现定时提醒

猿猿相抱 2008-11-15 11:24:24
如何实现定时提醒
具体通过什么实现。。
...全文
127 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ericllzh 2008-11-16
  • 打赏
  • 举报
回复
楼上已经很详细了。
在看下你自己的需求咯。
一般都用timer来实现的,或者你可以写个线程,死循环的读取现在的时间来进行判断。^_^。
如果说的什么不对,提出下啊,我比较菜。
  • 打赏
  • 举报
回复
用System.Threading.Timer
设定间隔时间,到时间执行提醒操作就可以了。

using System;
using System.Timers;

public class Timer1
{
public static void Main()
{
// Normally, the timer is declared at the class level, so
// that it doesn't go out of scope when the method ends.
// In this example, the timer is needed only while Main
// is executing. However, KeepAlive must be used at the
// end of Main, to prevent the JIT compiler from allowing
// aggressive garbage collection to occur before Main
// ends.
System.Timers.Timer aTimer = new System.Timers.Timer();

// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;

Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();

// Keep the timer alive until the end of Main.
GC.KeepAlive(aTimer);
}

// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
//execute your alert.
Console.WriteLine("Hello World!");
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧