C#中timer定时器用法实例
作者:令狐不聪 时间:2023-01-23 02:23:17
本文实例讲述了C#中timer定时器用法。分享给大家供大家参考。具体如下:
下面的代码通过Timer定时器每隔1000毫秒(1秒)触发一次事件
using System;
using System.Timers;
class TestTimer
{
public static void Main ()
{
Timer timer = new Timer();
timer.Elapsed + = new ElapsedEventHandler(DisplayTimeEvent);
timer.Interval = 1000;
timer.Start();
timer.Enabled = true;
while (Console.Read ()! = 'q')
{
//-------------
}
}
public static void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
Console.Write({0}, DateTime.Now);
}
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,timer,定时器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java之NIO基本简介
2021-12-20 22:15:44
![](https://img.aspxhome.com/file/2023/5/82335_0s.png)
基于c# Task自己动手写个异步IO函数
2021-08-06 12:07:56
![](https://img.aspxhome.com/file/2023/4/108664_0s.png)
Java中@ConfigurationProperties实现自定义配置绑定问题分析
2023-01-23 23:23:47
![](https://img.aspxhome.com/file/2023/4/90964_0s.png)
java实现斗地主发牌系统
2023-06-11 01:48:40
解决nacos升级spring cloud 2020.0无法使用bootstrap.yml的问题
2021-12-02 19:44:29
![](https://img.aspxhome.com/file/2023/3/61773_0s.png)
详细总结Java堆栈内存、堆外内存、零拷贝浅析与代码实现
2023-11-21 01:52:29
![](https://img.aspxhome.com/file/2023/5/59325_0s.png)
Android实现支付宝手势密码功能
2021-07-26 01:16:34
![](https://img.aspxhome.com/file/2023/1/137491_0s.jpg)
spring与mybatis三种整合方法
2021-11-27 22:00:46
Spring + Mybatis 项目实现动态切换数据源实例详解
2022-01-13 04:34:41
c# 断点续传的实现
2023-07-01 22:41:02
Java调用明华RF读写器DLL文件过程解析
2022-12-17 04:31:06
![](https://img.aspxhome.com/file/2023/2/105932_0s.png)
SpringMVC用JsonSerialize日期转换方法
2021-12-06 10:59:59
![](https://img.aspxhome.com/file/2023/2/70332_0s.jpg)
Java中的字节流文件读取教程(二)
2023-09-27 04:59:02
SpringBoot异步与事务一起使用的问题解决
2023-03-17 07:11:08
Android开发自定义双向SeekBar拖动条控件
2022-06-02 03:55:25
![](https://img.aspxhome.com/file/2023/1/139391_0s.png)
基于自定义Toast全面解析
2023-08-27 19:18:55
![](https://img.aspxhome.com/file/2023/7/98687_0s.jpg)
详解JS与APP原生控件交互
2022-11-21 21:28:15
![](https://img.aspxhome.com/file/2023/3/108303_0s.png)
Android 实现沉浸式状态栏的方法
2023-05-02 21:42:11
![](https://img.aspxhome.com/file/2023/6/120176_0s.gif)
Spring Security OAuth 自定义授权方式实现手机验证码
2021-10-03 23:30:27
![](https://img.aspxhome.com/file/2023/2/72282_0s.png)
C#实现文件上传及文件下载功能实例代码
2022-12-13 23:57:23