会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
BB.NET
每天一小步
博客园
首页
新随笔
联系
订阅
管理
项目需要刚写的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
posted @
2009-03-14 16:16
melody&amp;amp;bobo
阅读(
232
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告