简体   繁体   中英

Countdown Timer c#

Anybody knows how to add a Countdown Timer in c#

Ex:

I have the start time which is 5/2/2011 10:00:00 Am and set the static Duration to 7 Days

So.... the Time left will be 6 Days 12:00 hour till it reach zero. ends in -> 5/9/2011 10:00:00 Am

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.

In case you application reset you need to get the start point from somewhere (permanent storage). 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).

The .NET 4.0 includes the new System.Threading.CountdownEvent class you may find helpful.

A 7 Day timer in a asp.net page?

Perhaps your approach is wrong. Can you use winforms and install the application as a service instead?

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. IE call your server side method, or whatever.

If you have trouble with the technical aspects of this: jQuery countdown timer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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