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 = ;// 设置时间间隔为5秒
}
/// <summary>
/// 重发失败表通知
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void InvokeFailMsg(object sender, System.Timers.ElapsedEventArgs e)
{
//这里处理你定时重发的事件
}
}
}
C# 定时器-System.Timers.Timer的更多相关文章
- C# System.Timers.Timer定时器的使用和定时自动清理内存应用
项目比较大有时候会比较卡,虽然有GC自动清理机制,但是还是有不尽人意的地方.所以尝试在项目启动文件中,手动写了一个定时器,定时清理内存,加快项目运行速度. public class Program { ...
- System.Timers.Timer(定时器)
1.System.Timers命名空间下的Timer类.System.Timers.Timer类:定义一个System.Timers.Timer对象,然后绑定Elapsed事件,通过Start()方法 ...
- [C#]System.Timers.Timer
摘要 在.Net中有几种定时器,最喜欢用的是System.Timers命名空间下的定时器,使用起来比较简单,作为定时任务,有Quartz.net,但有时候,一个非常简单的任务,不想引入这个定时任务框架 ...
- 使用System.Timers.Timer类实现程序定时执行
使用System.Timers.Timer类实现程序定时执行 在C#里关于定时器类有3个:System.Windows.Forms.Timer类.System.Threading.Timer类和Sys ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法
System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...
- 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的差别和分别什么时候用
System.Windows.Forms.Timer.System.Timers.Timer.System.Threading.Timer的 区别和用法http://space.itpub.net/1 ...
- C# System.Timers.Timer中的坑,程序异常退出后timer依然运行问题
问题背景 C#小白,由于本公司IM系统服务端(java)是本人独立开发的,加上现在所在项目需要对接IM系统,于是IM的客户端(C#实现)对接工作就交给我了.于是C#小白的我天真的以为只要调用C#端的S ...
- Quartz.Net系列(十一):System.Timers.Timer+WindowsService实现定时任务
1.创建WindowsService项目 2.配置项目 3.AddInstaller(添加安装程序) 4.修改ServiceName(服务名称).StartType(启动类型).Description ...
随机推荐
- 浏览器css隐藏滚动条的方法!除了IE一般都支持
::-webkit-scrollbar { /* 滚动条整体部分 */ width:0px; margin-right:2px}::-webkit-scrollbar-track-piece { /* ...
- ArcGIS Runtime For Android 100.3天地图不加载问题
ArcGIS Runtime 100.3 不加载天地图问题 参考这篇帖子:https://community.esri.com/thread/220496-1003-webtiledlayer-can ...
- k8s probe
livenessProbe: httpGet: path: /abc/401 port: 8384 scheme: HTTP
- ORACLE 查询近一天,近半小时内的数据
SELECT 字段 FROM 表名 WHERE 时间字段 BETWEEN SYSDATE-1 AND SYSDATE; //查询一天内的数据 sysdate+1 加一天sysdate+1/24 ...
- 《JavaScript DOM编程艺术》学习笔记(三)
终于要完成这最后一部分了,距离第二部分已经过去五天了,一直想早点写的,但还是拖到今天了………… 34.position属性的和法制:static是position属性的默认值,意思是有关元素将按照它们 ...
- ABP入门系列(5)——展现层实现增删改查
ABP入门系列目录--学习Abp框架之实操演练 这一章节将通过完善Controller.View.ViewModel,来实现展现层的增删改查.最终实现效果如下图: 一.定义Controller ABP ...
- 在ASP.NET Core中使用brotli压缩
Brotli是一种全新的数据格式,可以提供比Zopfli高20-26%的压缩比.据谷歌研究,Brotli压缩速度同zlib的Deflate实现大致相同,而在Canterbury语料库上的压缩密度比LZ ...
- 脚本语言丨Batch入门教程第三章:逻辑判断
通过学习Batch入门教程的前两章内容,我们已经大致掌握了基本概念和认识变量的相关内容,今天我们要跟大家继续分享第三章内容:Batch入门教程之逻辑判断. 前期回顾 ◀Batch入门教程丨部署与H ...
- [Swift]LeetCode42. 接雨水 | Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [Swift]LeetCode691. 贴纸拼词 | Stickers to Spell Word
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...