zoukankan
html css js c++ java
项目需要刚写的Timer
Code
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Text;
4
using
System.Timers;
5
6
7
namespace
Server
8
{
9
public
class
Stimer
10
{
11
private
int
times, _timers;
12
private
Timer t;
13
/**/
///
<summary>
14
///
Elapsed事件的频率 单位:秒
15
///
</summary>
16
public
int
Interval
17
{
18
set
{
this
.times
=
value; }
19
}
20
public
Stimer(
int
_t)
21
{
22
t
=
new
Timer(
1000
);
//
配置间隔时间为1000毫秒;
23
t.Elapsed
+=
new
ElapsedEventHandler(t_Elapsed);
24
t.AutoReset
=
true
; ;
//
配置是执行一次(false)还是一直执行(true);
25
t.Enabled
=
false
;
//
是否执行System.Timers.Timer.Elapsed事件;
26
this
.times
=
_t;
27
this
._timers
=
_t;
28
}
29
public
void
Start()
30
{
31
t.Start();
32
}
33
public
void
Stop()
34
{
35
t.Stop();
36
}
37
public
void
Restart()
38
{
39
t.Stop();
40
this
._timers
=
times;
41
t.Start();
42
}
43
public
void
Dispose()
44
{
45
t.Stop();
46
t.Dispose();
47
}
48
49
public
void
TimeOut()
50
{
51
Console.WriteLine(
"
aaaa
"
);
52
}
53
void
t_Elapsed(
object
sender, ElapsedEventArgs e)
54
{
55
if
(_timers
==
0
)
56
{
57
_timers
=
times;
58
TimeOut();
59
}
60
else
61
{
62
_timers
--
;
63
}
64
}
65
}
66
}
67
查看全文
相关阅读:
CentOS 6.9/7通过yum安装指定版本的MySQL
CentOS的el5, el6, el7代表什么
MySQL的mysql.sock文件作用(转)
MySQL常用命令
Linux下以特定用户运行命令
简述TCP的三次握手过程
Tomcat-connector的微调(1): acceptCount参数
tomcat修改jsessionid在cookie中的名称
使用@Async异步注解导致该Bean在循环依赖时启动报BeanCurrentlyInCreationException异常的根本原因分析,以及提供解决方案【享学Spring】
[LeetCode] Construct the Rectangle 构建矩形
原文地址:https://www.cnblogs.com/bobofsj11/p/1411628.html
最新文章
正则进阶
C# 有道API翻译
百度翻译接口使用c#
领域模型
图解单链表反转
C# 类中发生数据变化的属性
HTTP状态码
PowerDesigner导出表为Excel(转)
PowerDesigner导出图片
CentOS的update-grub2命令
热门文章
CentOS 7挂载磁盘提示: mount: unknown filesystem type 'LVM2_member'
MyBatis连接SQL Server的关键点
PostgreSQL控制台以竖行显示
MySQL在控制台上以竖行显示表格数据
CentOS 7修改网卡名为eth0
PostgreSQL各命令行工具功能说明
PostgreSQL教程收集(中文文档/命令行工具/常用命令)
PostgreSQL远程连接配置管理/账号密码分配(解决:致命错误: 用户 "postgres" Ident 认证失败)
PostgreSQL高可用集群方案收集/主从切换/一主多从(待实践)
PostgreSQL修改数据库目录/数据库目录迁移
Copyright © 2011-2022 走看看