C# 定时器-System.Timers.Timer

using Newtonsoft.Json;
using Rafy;
using Rafy.Domain;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DBI.SaaS.MessageService.Controller
{
    public class TimersInvoke
    {
        private LogController log;
        public TimersInvoke()
        {
            this.log = new LogController();
        }
        System.Timers.Timer timer = new System.Timers.Timer();
        public void StartTimer()
        {
            timer.Elapsed += new System.Timers.ElapsedEventHandler(InvokeFailMsg);
            timer.Enabled = true;//是否触发Elapsed事件
            timer.AutoReset = true; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true)
            timer.Interval = 5000;// 设置时间间隔为5秒
        }
        /// <summary>
        /// 重发失败表通知
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void InvokeFailMsg(object sender, System.Timers.ElapsedEventArgs e)
        {
            //这里处理你定时重发的事件
        }
    }
}

 

posted @ 2017-03-14 14:07  一指流砂~  阅读(5080)  评论(1编辑  收藏  举报