C#timer做java timer 倒计时时

下次自动登录
现在的位置:
& 综合 & 正文
ios 简单的倒计时验证码数秒过程实现
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
//倒计时方法验证码实现倒计时60秒,60秒后按钮变换开始的样子
-(void)timerFireMethod:(NSTimer *)theTimer {
if (seconds == 1) {
[theTimer invalidate];
seconds = 60;
[validCodeBtn_ setTitle:@"获取验证码" forState: UIControlStateNormal];
[validCodeBtn_ setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[validCodeBtn_ setEnabled:YES];
seconds--;
NSString *title = [NSString stringWithFormat:MSG_DYNAMIC_CODE_WAIT,seconds];
[validCodeBtn_ setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[validCodeBtn_ setEnabled:NO];
[validCodeBtn_ setTitle:title forState:UIControlStateNormal];
//如果登陆成功,停止验证码的倒数,
- (void)releaseTImer {
if (timer) {
if ([timer respondsToSelector:@selector(isValid)]) {
if ([timer isValid]) {
[timer invalidate];
seconds = 60;
&&&&推荐文章:
【上篇】【下篇】[C#]&Timer计时器
问题描述:在线程里有一个需要倒计时的功能,本来使用工具栏里的Timer控件,结果发现无法进入Timer的循环方法,单独拿出来调试Timer控件时,发现正常使用ok的,怀疑是线程与Timer的问题。
查阅相关资料后发现:
其他线程是无法控制Form下的Timer,一般可使用System.Timer或System.Threading.Timer
一定要用Form下的Timer的话,用异步委托来实现!
解决方法:
使用System.Timer.Timer来代替,功能ok。
C#中timer类的用法:
关于C#中timer类&
在C#里关于定时器类就有3个&&
1.定义在System.Windows.Forms里&&
2.定义在System.Threading.Timer类里&&
3.定义在System.Timers.Timer类里
System.Windows.Forms.Timer是应用于WinForm中的,它是通过Windows消息机制实现的,类似于VB或Delphi中的Timer控件,内部使用API&
SetTimer实现的。它的主要缺点是计时不精确,而且必须有消息循环,Console&
Application(控制台应用程序)无法使用。&&
System.Timers.Timer和System.Threading.Timer非常类似,它们是通过.NET&
Pool实现的,轻量,计时精确,对应用程序、消息没有特别的要求。System.Timers.Timer还可以应用于WinForm,完全取代上面的Timer控件。它们的缺点是不支持直接的拖放,需要手工编码。
使用System.Timers.Timer类
//实例化Timer类,设置间隔时间为10000毫秒;
System.Timers.Timer t = new
System.Timers.Timer(10000);
//到达时间的时候执行事件;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);
t.AutoReset =//设置是执行一次(false)还是一直执行(true);
t.Enabled =//是否执行System.Timers.Timer.Elapsed事件;
====================================
自己写的一个用System.Timer类的方法
&1&public&class&BF_CheckUpdate
&3&&&&&&&&&private&static&object&LockObject&=&new&Object();
&5&&&&&&&&&//&定义数据检查Timer
&6&&&&&&&&&private&static&Timer&CheckUpdatetimer&=&new&Timer();
&8&&&&&&&&&//&检查更新锁
&9&&&&&&&&&private&static&int&CheckUpDateLock&=&0;
11&&&&&&&&&///
12&&&&&&&&&///&设定数据检查Timer参数
13&&&&&&&&&///
14&&&&&&&&&internal&static&void&GetTimerStart()
15&&&&&&&&&{
16&&&&&&&&&&&&&//&循环间隔时间(10分钟)
17&&&&&&&&&&&&&CheckUpdatetimer.Interval&=&600000;
18&&&&&&&&&&&&&//&允许Timer执行
19&&&&&&&&&&&&&CheckUpdatetimer.Enabled&=&
20&&&&&&&&&&&&&//&定义回调
21&&&&&&&&&&&&&CheckUpdatetimer.Elapsed&+=&new&ElapsedEventHandler(CheckUpdatetimer_Elapsed);
22&&&&&&&&&&&&&//&定义多次循环
23&&&&&&&&&&&&&CheckUpdatetimer.AutoReset&=&
24&&&&&&&&&}
26&&&&&&&&&///
27&&&&&&&&&///&timer事件
28&&&&&&&&&///
29&&&&&&&&&///
30&&&&&&&&&///
31&&&&&&&&&private&static&void&CheckUpdatetimer_Elapsed(object&sender,&ElapsedEventArgs&e)
32&&&&&&&&&{
33&&&&&&&&&&&&//&加锁检查更新锁
34&&&&&&&&&&&&&lock&(LockObject)
35&&&&&&&&&&&&&{
36&&&&&&&&&&&&&&&&&if&(CheckUpDateLock&==&0)&CheckUpDateLock&=&1;
37&&&&&&&&&&&&&&&&&else&
38&&&&&&&&&&&&&}&&&&&&&&&
39&&&&&&&&&&&
40&&&&&&&&&&&&//More&code&goes&here<img ALT="" src="/blog7style/images/common/sg_trans.gif" real_src ="/Images/dot.gif"
TITLE="[C#]&Timer计时器" /><img ALT="" src="/blog7style/images/common/sg_trans.gif" real_src ="/Images/dot.gif"
TITLE="[C#]&Timer计时器" />.
41&&&&&&&&&&&//具体实现功能的方法
42&&&&&&&&&&&&Check();
43&&&&&&&&&&&&&&&//&解锁更新检查锁
44&&&&&&&&&&&&&lock&(LockObject)
45&&&&&&&&&&&&&{
46&&&&&&&&&&&&&&&&&CheckUpDateLock&=&0;
47&&&&&&&&&&&&&}&&&&&&&&&&&&
48&&&&&&&&&}
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。C#中实现倒计时功能_Linux编程_Linux公社-Linux系统门户网站
你好,游客
C#中实现倒计时功能
来源:Linux社区&
作者:Linux
今天小编要和大家分享的是利用C#实现倒计时的功能,希望对大家有所帮助。
本实例是通过使用timer组件来实现倒计时功能的,实现步骤如下:
(1)首先创建两个窗体,在Form1窗体上添加一个Button按钮和一个timer组件,用来执行倒计时功能;在Form2中添加一个Label控件,用于显示倒计时。
(2)在Form2窗体中定义一个公共变量curr_time,用于为Label控件赋值,代码如下:
Public string curr_time
&&&&&&& Return lable1.T
&&&&&& Label1.Text=
(3)&&&&&&&&&&&&& 在Form1窗体中,首先定义一个TimeSpan类对象,用于设定初始值;其次在Button按钮的Click事件下,激活timer组件,使其开始计时;然后在timer组件的Tick事件下,使用TimeSpan类对象的Subtract方法,在指定时间间隔内循环减1,实现倒计时功能。主要代码如下:
Private TimeSpan ts=new TimeSpan(0,5,0);
Private Form2 frm=
Private void button1_Click(object sender,System.EventArgs e)
&& Timer1.Enabled =
&& Frm=new Form2();
&& Frm.ShowDialog(this);
Private void timer1_Tick(object sender,System.EventArgs e)
&& String str=ts.Hours.ToString()+”:”+ts.Minutes.ToString()+”:”+ts.Seconds.ToString();
Frm.curr_time=
Ts=ts.Subtract(new TimeSpan(0,0,1));
If(ts.TotalSeconds&0.0)
&& Time1.Enabled=
相关资讯 & & &
& (06月10日)
& (06月10日)
& (08月14日)
& (06月10日)
& (06月09日)
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款js倒计时代码 支持同一页面多个倒计时代码 - 化蝶自在飞的博客 - ITeye技术网站
博客分类:
js倒计时代码:
&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&
&title&js倒计时代码 - k686绿色软件 - &/title&
&meta name="Generator" content="EditPlus"&
&meta name="Author" content="k686绿色软件 "&
&meta name="Keywords" content="绿色软件"&
&meta name="Description" content="绿色软件"&
k686绿色软件 -
function countDown( maxtime,fn )
var timer = setInterval(function()
if(maxtime&=0){
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
msg = "距离结束还有"+minutes+"分"+seconds+"秒";
fn( msg );
if(maxtime == 5*60) alert('注意,还有5分钟!');
clearInterval( timer );
fn("时间到,结束!");
&div id="timer1" style="color:red"&&/div&
&div id="timer2" style="color:red"&&/div&
countDown( 6,function( msg )
document.getElementById('timer1').innerHTML =
countDown( 6000,function( msg )
document.getElementById('timer2').innerHTML =
忠心感谢来自Q群的wait提供的代码: /svn/trunk/tdemos/countDown.html
此代码的优点在于调用时可不用对功能代码做任何修改.需要显示的地方设定容器id,然后输出一小段代码,一个页面无限制倒计时个数:
countDown( 6,function( msg )
document.getElementById('timer1').innerHTML =
下面一段代码是来自同一个交流群的大神Vilic优化简写后的代码,在此一并表示感谢:
&!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&
&html xmlns=" http://www.w3.org/1999/xhtml"&
&title&Timer - by Vilic JavaScriptQQ交流群&/title&
&div id="timer1"&&/div&
&div id="timer2"&&/div&
&div id="timer3"&&/div&
&script type="text/javascript"&
var addTimer = function () {
var list = [],
return function (id, time) {
if (!interval)
interval = setInterval(go, 1000);
list.push({ ele: document.getElementById(id), time: time });
function go() {
for (var i = 0; i & list. i++) {
list[i].ele.innerHTML = getTimerString(list[i].time ? list[i].time -= 1 : 0);
if (!list[i].time)
list.splice(i--, 1);
function getTimerString(time) {
var not0 = !!time,
d = Math.floor(time / 86400),
h = Math.floor((time %= 86400) / 3600),
m = Math.floor((time %= 3600) / 60),
s = time % 60;
return "还有" + d + "天" + h + "小时" + m + "分" + s + "秒";
else return "时间到";
addTimer("timer1", 12);
addTimer("timer2", 10);
addTimer("timer3", 13);
化蝶自在飞
浏览: 1491437 次
来自: 武汉
增加一个微信内置浏览器的useragent:
Mozilla/ ...
leiliang10 写道你揍是个骗纸此话怎讲?这个工具是我自 ...
你揍是个骗纸
代码有吗。
关闭所有弹窗
var list = a ...C#如何利用timer做成倒计时,显示分钟和秒
[问题点数:20分,结帖人luckdong0207]
C#如何利用timer做成倒计时,显示分钟和秒
[问题点数:20分,结帖人luckdong0207]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2002年10月 VC/MFC大版内专家分月排行榜第一2004年1月 软件工程/管理大版内专家分月排行榜第一2003年1月 软件工程/管理大版内专家分月排行榜第一
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 timer倒计时 的文章

 

随机推荐