Skip to content

Looping timer?

jack

Asked Jun 17, 2006, 7:43 AM EDT2 answers
Share
LinkedInX
hey,
sorry if this is a newbieish question but what I am attempting to do is create a timer that resets itself and starts again when it hits 0. The ammount of time is first entered by a user into a text box.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You need to be more specific, but you can start by checking out the System.TimeSpan and System.DateTime classes.

    I guess an example scenario might be... a form that has a timer, textbox, and button...

    textbox could be defined to be minutes, or it could be parsed from some predefined format... anyways...
     
    lets say the button defines a variable "minutes" which comes from the textbox text, and it sets a DateTime object to DateTime.Now, getting the current time. the button also activates the timer...

    the timer's speed should be fast, but not so fast as to be wasteful... when the timer sees that

    ((TimeSpan)(DateTime.Now - time_when_user_pressed_button)).TotalMinutes

    is greater than "minutes", then the timer can do stuff, like reset, turn itself off, etc, etc
    0
  • 0
    sorry for not being specific enough.. i did some looking around the site... the closest thing to what i require is  at http://www.c-sharpcorner.com/Code/2003/Aug/EggTimer.asp  but what i would like to be able to do is when the timer gets to 0 and triggers the sound/event/whatever for the timer to auto reset to the previously entered ammount of time and also automatically start again.
    0