在特定时间发生火灾 [英] Fire event on specific time

查看:60
本文介绍了在特定时间发生火灾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用System.Threading.Timer在一段时间后触发事件,这工作正常.即

Hi All,

I am using System.Threading.Timer to fire event after some time, which is working fine. i.e.

timervar = new System.Threading.Timer(methodname, null, 60000, 0);



我也想在特定时间使用相同事件触发事件.可能吗?如果是,那怎么办?

问候!
Aman



I also want to fire event on specific time using the same. Is it possible? If yes, then how?

Regards!
Aman

推荐答案

一种方法,获取当前时间,获取当前时间与计划时间之差后,等待该持续时间并触发事件
One approach, Get the current time, after get the difference between current and scheduled time, wait till that duration and fire the event


我使用了Brij推荐的方法并获得了结果.代码如下:

I used the approach recommended by Brij and achieved the result. the code is following:

TimeSpan myTimeSpan1 = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
TimeSpan myTimeSpan2 = new TimeSpan(20, 00, 00);
TimeSpan TsObj = new TimeSpan();
TsObj = myTimeSpan2.Subtract(myTimeSpan1);
Int32 milsec = Convert.ToInt32(TsObj.TotalMilliseconds);
My_Timer = new System.Threading.Timer(timer_click, null, milsec, 0);



感谢发布.



Thanx for posting.


使用asp.net计时器控件在某个时间间隔触发事件
use asp.net timer control for firing event on some time interval


这篇关于在特定时间发生火灾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆