zoukankan
html css js c++ java
System.Threading.TimerCallback 永不停止的定时器
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Threading;
namespace
ConsoleApplication1
{
class
TimerExample
{
static
void
Main(
string
[] args)
{
AutoResetEvent autoEvent
=
new
AutoResetEvent(
false
);
StatusChecker statusChecker
=
new
StatusChecker(
10
);
TimerCallback timerDelegate
=
new
TimerCallback(statusChecker.CheckStatus);
Console.WriteLine(
"
服务器开始扫描:
"
+
DateTime.Now.ToString(
"
h:mm:ss.fff
"
));
Timer stateTimer
=
new
Timer(timerDelegate, autoEvent,
1000
,
5000
);
autoEvent.WaitOne(
-
1
,
false
);
stateTimer.Dispose();
Console.WriteLine(
"
xxxxxxxx.
"
);
}
}
class
StatusChecker
{
int
invokeCount, maxCount;
public
StatusChecker(
int
count)
{
invokeCount
=
0
;
maxCount
=
count;
}
//
This method is called by the timer delegate.
public
void
CheckStatus(Object stateInfo)
{
//
AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
Console.WriteLine(
"
{0} Checking status {1,2}.
"
,
DateTime.Now.ToString(
"
h:mm:ss.fff
"
),
(
++
invokeCount).ToString());
//
if (invokeCount == maxCount)
//
{
//
//
Reset the counter and signal Main.
//
invokeCount = 0;
//
autoEvent.Set();
//
}
}
}
}
查看全文
相关阅读:
安装sublime text2 for ubuntu
ruby中Regexp用法
rvm is not a function的解决方法
解决启动mongod 时,出现addr already in use错误
rails中常用的插件
在数据库中存储层次数据
Formtastic: Forms Made Crazy Easy for Rails Developers
rails安全性
Rails 增加一个模型(model)
RPC框架实现思路浅析
原文地址:https://www.cnblogs.com/kokoliu/p/1171621.html
最新文章
zabbix问题汇总
利用phpize 外挂php扩展
Linux下压缩音频文件
Debian8搭建php环境
为Debian/Ubuntu的apt-get install添加自动补齐/完成功能
pptpd
PyQt 自定义信号带参数
PyQt之布局&无边框&信号
第一个PyQt程序
vue 常用手册
热门文章
axios中文文档
Vue2.0学习——axios用法详解
vue中使用axios最详细教程
input时间表单默认样式修改(input[type="date"])
移动端上拉加载下拉刷新插件-mescroll.js插件
CSS3 鲜为人知的属性-webkit-tap-highlight-color的理解
jQuery懒加载插件 – jquery.lazyload.js简单调用
html5的audio实现高仿微信语音播放效果(实际项目)
html5的audio实现高仿微信语音播放效果Demo
Rails中实现批量删除
Copyright © 2011-2022 走看看