简体   繁体   English

倒数计时器 c#

[英]Countdown Timer c#

Anybody knows how to add a Countdown Timer in c#任何人都知道如何在 c# 中添加倒数计时器

Ex:前任:

I have the start time which is 5/2/2011 10:00:00 Am and set the static Duration to 7 Days我的开始时间是 2011 年 5 月 2 日上午 10:00:00 ,并将static持续时间设置为7 天

So.... the Time left will be 6 Days 12:00 hour till it reach zero.所以....剩下的时间将是6 天 12:00 小时,直到它达到零。 ends in -> 5/9/2011 10:00:00 Am结束于 -> 2011 年 5 月9 日上午 10:00:00

Note: The Time Left can not be reset and start over again.. and it depends only on the Start Time注意:剩余时间不能重置并重新开始..它仅取决于开始时间

I don't know how to do this.. any help I will be grateful.我不知道该怎么做..任何帮助我将不胜感激。

You need a permanent storage (on hard disk) like registry, database or XML file because any time span greater than ~24h is not guaranteed in a in-memory code in ASP.NET.您需要一个永久存储(在硬盘上),如注册表、数据库或 XML 文件,因为在 ASP.NET 的内存代码中不能保证任何大于 ~24 小时的时间跨度。

In case you application reset you need to get the start point from somewhere (permanent storage).如果您的应用程序重置,您需要从某个地方(永久存储)获取start point Usually when there's no request from clients you application would be unloaded without notice (you loose the in-memory data).通常,当没有来自客户端的请求时,您的应用程序会在不通知的情况下被卸载(您会丢失内存中的数据)。 Also ASP.NET recycles applications based on some configurations in IIS (application pool you are using for your application).此外,ASP.NET 根据 IIS(您用于应用程序的应用程序池)中的某些配置recycles应用程序。

The .NET 4.0 includes the new System.Threading.CountdownEvent class you may find helpful. .NET 4.0包括新的System.Threading.CountdownEvent class,您可能会觉得有帮助。

A 7 Day timer in a asp.net page? asp.net 页面中的 7 天计时器?

Perhaps your approach is wrong.也许你的方法是错误的。 Can you use winforms and install the application as a service instead?您可以使用 winforms 并将应用程序安装为服务吗?

I guess if it has to be a webpage, do the timer in JavaScript (perhaps use JQuery), and when its done, do what you want through JQuery.我想如果它必须是一个网页,请在 JavaScript(可能使用 JQuery)中执行计时器,完成后,通过 JQuery 执行您想要的操作。 IE call your server side method, or whatever. IE 调用你的服务器端方法,或者其他什么。

If you have trouble with the technical aspects of this: jQuery countdown timer如果您对此技术方面有疑问: jQuery 倒数计时器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM