/// <summary>
/// 定时器
/// </summary>
public void TimeDo()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(TimeEvent);
aTimer.Interval = 1000;
aTimer.Enabled = true;
}
/// <summary>
/// 定时器触发事件
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
private static void TimeEvent(object source, System.Timers.ElapsedEventArgs e)
{
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
int iHour = 10;
int iMinute = 30;
int iSecond = 00;
// 设置 每秒钟的开始执行一次
if (intSecond == iSecond)
{
Console.WriteLine("
c# 利用Time实现定时启动程序
最新推荐文章于 2023-09-19 17:21:32 发布
本文介绍了如何在C#中利用System.Timers.Timer类创建定时器,通过设定间隔时间来触发特定事件。在TimeEvent方法中,根据SignalTime判断小时、分钟和秒数,实现每秒、每30分钟以及每天10:30:00启动程序的功能。

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



