如何创建计时器 [英] how to create a timer

查看:102
本文介绍了如何创建计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想创建一个计时器。当用户登录并单击开始按钮时,计时器应该开始。当用户点击停止按钮时,计时器应该停止。无论他是否退出,如果他再次登录,计时器应该继续。

考虑员工登录的同义词。他登录并开始时间。当再次登录时,计时器应显示总时间,即从开始时间到当前时间。

解决方案

你可能需要一个

列表< datetime> < /   datetime  >  

用于保存用户的开始时间,以及

列表< timespan> < /   timespan  >  

用于保存总用户次数。

当用户启动时,将他的开始时间设置为DateTime.Now,当他停止时,将时差添加到用户的TimeSpans项目


那么什么我们可以帮你吗?这里没有人会为你做代码,所以请更好地遵循这些教程和讨论,并计划如何为自己制作一个代码。

asp.net使用c#(倒数计时器) [ ^ ]

http://www.devmanuals.com/tutorials/ms/aspdotnet/timer.html [ ^ ]

http://hemantrautela.blogspot.com/2012/09/timer-ajax-control-cnet-aspnet.html [ ^ ]

http://www.dotnetperls.com/timer [ ^ ]

http://stackoverflow.com/questions/12786131/regarding-count-down-timer-in-asp-net-c-sharp [ ^ ]


< asp:scriptmanager id =ScriptManager1runat =serverxmlns:asp =#unknown>



< asp:timer id =Timer1 runat =serverontick =Timer1_Tickinterval =1000enabled =falsexmlns:asp =#unknown>



< asp :updatepanel id =UpdatePanel1runat =serverxmlns:asp =#unknown>

< contenttemplate>

< asp:label id = Label1runat =servertext =Labelforecolor =Redborderstyle =None>



< triggers>< asp:asyncpostbacktrigger controlid =Timer1eventname =Tick>





< pre lang =c#> protected void Timer1_Tick( object sender,EventArgs e)
{

string d1 = DateTime.Now.ToLongTimeString();
DateTime d2 = Convert.ToDateTime( 09:00:00 AM);


TimeSpan t =(Convert.ToDateTime(d1))。减去(d2);

Label1.Text = t.Hours.ToString()+ + t.Minutes.ToString()+ + t.Seconds.ToString();

}


Hi,
i want to create a timer. the timer should begin when the user sign in and click on start button. and the timer should stop when the user click on stop button. no matter if he logs out,if he sign in again the timer should be continued.
consider a synareo of employee login. he logins and starts the time. and when is login again the timer should show the total time i.e from start time to current time.

解决方案

you'll probably need a

List<datetime></datetime>

for saving users starting times, and a

List<timespan></timespan>

for saving total users times.
When the user starts, set his starting time to DateTime.Now, when he stops, add the time difference to the TimeSpans item of the user


So what can we do for you? No one here will do code for you,so better follows these tutorials and discussions and plan how to make one for yourself..
asp.net using c#( countdown timer)[^]
http://www.devmanuals.com/tutorials/ms/aspdotnet/timer.html[^]
http://hemantrautela.blogspot.com/2012/09/timer-ajax-control-cnet-aspnet.html[^]
http://www.dotnetperls.com/timer[^]
http://stackoverflow.com/questions/12786131/regarding-count-down-timer-in-asp-net-c-sharp[^]


<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">

<asp:timer id="Timer1" runat="server" ontick="Timer1_Tick" interval="1000" enabled="false" xmlns:asp="#unknown">

<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
<contenttemplate>
<asp:label id="Label1" runat="server" text="Label" forecolor="Red" borderstyle="None">

<triggers><asp:asyncpostbacktrigger controlid="Timer1" eventname="Tick">


protected void Timer1_Tick(object sender, EventArgs e)
   {

       string d1 = DateTime.Now.ToLongTimeString();
       DateTime d2 = Convert.ToDateTime("09:00:00 AM");


       TimeSpan t = (Convert.ToDateTime(d1)).Subtract(d2);

       Label1.Text = t.Hours.ToString() + ":" + t.Minutes.ToString() + ":" + t.Seconds.ToString();

   }


这篇关于如何创建计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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