0

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.

gsharp
  • 27,557
  • 22
  • 88
  • 134
booody
  • 79
  • 3
  • 14
  • 1
    The ASP.Net runtime will recycle the application pool, so nothing should be sitting around for 7 days without seriously impacting on other things. Suggest maybe looking at Windows Workflow Foundation, which is designed with longer-running tasks in mind. You can host WF inside ASP.Net, but it would persist it's state until resuming a bookmark, so it wouldn't cripple the server for 7 days at a time. – RichardW1001 May 01 '11 at 22:30
  • What are you actually trying to do? Is an in-memory countdown really the best approach? Why not persist a date-time value in some form, and then when needed compare against current time? – RichardW1001 May 01 '11 at 22:31
  • Thanks every one for the help ... I solved the problem & found the solution ... – booody May 03 '11 at 19:08
  • please write your own answer and mark it ;-) – gsharp May 04 '11 at 16:33

2 Answers2

1

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.

Xaqron
  • 29,931
  • 42
  • 140
  • 205
0

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

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

Community
  • 1
  • 1
Greg Randall
  • 811
  • 7
  • 14