官方文档

https://msdn.microsoft.com/zh-cn/library/system.timers.timer.aspx

using System;
using System.Timers; public class Example
{
private static System.Timers.Timer aTimer; public static void Main()
{
SetTimer(); Console.WriteLine("\nPress the Enter key to exit the application...\n");
Console.WriteLine("The application started at {0:HH:mm:ss.fff}", DateTime.Now);
Console.ReadLine();
aTimer.Stop();
aTimer.Dispose(); Console.WriteLine("Terminating the application...");
} private static void SetTimer()
{
// Create a timer with a two second interval.
aTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
} private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{
Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}",
e.SignalTime);
}
}
// The example displays output like the following:
// Press the Enter key to exit the application...
//
// The application started at 09:40:29.068
// The Elapsed event was raised at 09:40:31.084
// The Elapsed event was raised at 09:40:33.100
// The Elapsed event was raised at 09:40:35.100
// The Elapsed event was raised at 09:40:37.116
// The Elapsed event was raised at 09:40:39.116
// The Elapsed event was raised at 09:40:41.117
// The Elapsed event was raised at 09:40:43.132
// The Elapsed event was raised at 09:40:45.133
// The Elapsed event was raised at 09:40:47.148
//
// Terminating the application...

C# Timer自带定时器的更多相关文章

  1. Java 中Timer和TimerTask 定时器和定时任务使用的例子

    转自:http://blog.csdn.net/kalision/article/details/7692796 这两个类使用起来非常方便,可以完成我们对定时器的绝大多数需求 Timer类是用来执行任 ...

  2. java_Timer_schedule jdk自带定时器

    定时器经常在项目中用到,定制执行某些操作,比如爬虫就需要定时加载种子等操作,之前一直用spring的定制器近期做项目发现,jdk有很简单的提供 代码如下 1 /* * Copyright (c) 20 ...

  3. Go语言协程并发---timer秒表与定时器

    秒表 package main import ( "fmt" "time" ) /*每秒大喊我要去浪,共9次,然后退出计时*/ func main() { va ...

  4. (转)ASP.net中Timer无刷新定时器.

    Timer控件要实现无刷新,得用到ajax技术 首先得添加一个ScriptManager控件,然后再添加一个UpdatePanel用于存放Timer控件内容的,就可以实现无刷新了.下面是详细的内容: ...

  5. spring自带定时器

    http://www.cnblogs.com/pengmengnan/p/6714203.html 注解模式的spring定时器1 , 首先要配置我们的spring.xmlxmlns 多加下面的内容. ...

  6. constant timer(固定定时器),constant throughput timer(常数吞吐量定时器);多个请求,某个请求a下,设置常数吞吐量定时器,模式:all active threads(shared)则所有请求吞吐量一致;

    1.两请求之间添加'固定定时器' 1000ms,那么两请求发送间隔时间是多少? 1000ms吗? 由实验得出,2个请求发送间隔时间 = 1000ms + 第一个请求时间(发出至完成后时间) 2.单个请 ...

  7. QT 按钮类继承处理带定时器

    01.class KeyButton : public QPushButton  02.{  03.    Q_OBJECT  04.public:  05.    explicit KeyButto ...

  8. Windows内核开发-6-内核机制 Kernel Mechanisms

    Windows内核开发-6-内核机制 Kernel Mechanisms 一部分Windows的内核机制对于驱动开发很有帮助,还有一部分对于内核理解和调试也很有帮助. Interrupt Reques ...

  9. C# 在类中使用Timer定时器以及延时处理的方法

    我们平时在C#中要用到定时功能时,有自带定时器,一般在定时器里面写函数就行了,现在需要在类里面写了一个定时器,不和界面绑定,一开始的时候感觉没什么思路,然后看了一下界面的设计代码,有了思路,还是很简单 ...

随机推荐

  1. 编程精粹--编写高质量C语言代码(1):假想编译程序

    编译程序只能查找出程序的语法错误,而对于"数组越界訪问","对空指针解引用"等错误.编译程序是束手无策的.同一时候我们知道測试人员所使用的黑箱測试方法所能做的不 ...

  2. App.config 中读写appSettings、system.serviceModel终结点,以及自定义配置节

    转自:http://blog.csdn.net/chelen_jak/article/details/8190795 感觉写的很好,推荐

  3. mkyaffs2image编译

    http://blog.chinaunix.net/uid-26009923-id-3760474.htmlhttp://blog.csdn.net/xingtian19880101/article/ ...

  4. SpringMVC 拦截器实现

    SpringMvc实现拦截器方式一: <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**&q ...

  5. [转]ListView学习笔记(二)——ViewHolder

    在android开发中Listview是一个很重要的组件,它以列表的形式根据数据的长自适应展示具体内容,用户可以自由的定义listview每一列的布局,但当listview有大量的数据需要加载的时候, ...

  6. mysql 授权的时候库名不能添加单引号homestead.* 写成 '库名'.* 错的语法

    create user 'wechat'@'192.168.10.%' identified by 'xxxxx'; create database 库名DEFAULT CHARSET utf8 CO ...

  7. sparkr基本操作1

    由于装的sparkr是1.4版本的,老版本的很多函数已经不再适用了. 在2台服务器的组成的集群中测试了一版数据,熟悉下这个api的基本操作.​ libpath <- .libPaths() li ...

  8. 成员函数后面加const,没有const,以及使用的区别

    函数后面加const 编译器会自动给每一个函数加一个this指针.在一个类的函数后面加上const后,就表明这个函数是不能改变类的成员变量的(加了mutable修饰的除外,后面有讲).实际上,也就是对 ...

  9. nginx反向代理压测问题记录

    使用nginx反向代理压测web程序,100个用户并发时,每隔一段时间loadrunner工具中就会报错,报错信息如下: Continuing after Error -26610: HTTP Sta ...

  10. OPenGL 库文件的添加

    OPenGL使用前必须添加一些必要的库文件: 需要安装 GLUT 工具包: GLUT下载地址   GLAUX下载地址 Windows 环境下安装 GLUT 的步骤:1.将下载的压缩包解开,将得到 5 ...