Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

help with a timer

timer countdown

  • Please log in to reply
7 replies to this topic

#1 mitchel0

mitchel0

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 25 April 2011 - 12:48 PM

hey guys, i need help with writing a timers current time to a string, then to display the string. i tried
dis.tostring()
and then but i cannont get the timer to show the countdown, but i cannot :( if you guys could help, id love it!
  • 0

#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 25 April 2011 - 01:00 PM

I don't believe you can get the time elapsed from a Timer object, as that's not what it's for, but rather for the execution of some code at regular intervals. If you need to know how much time has elapsed, you can have your timer callback function increment a variable each time it is called, and multiply that number by the timer's interval property to get the time elapsed.

Incidentally, which timer are you referring to? System.Threading.Timer or System.Timers.Timer?
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3 mitchel0

mitchel0

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 25 April 2011 - 02:17 PM

hmm, ok then how could i show how much time until something happens then?
  • 0

#4 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 25 April 2011 - 06:19 PM

Same thing, but in reverse. Keep a variable of the amount of time you want to wait until an event happens. In the timer's callback method, subtract a certain amount from that variable, and check it to see if it is less than or equal to zero. If it is, then your time has expired and you can have it do something else.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#5 mitchel0

mitchel0

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 26 April 2011 - 02:33 AM

hmmm seems easy enough, but how do i actually display on the gui the time left? and im using whatever timer you get when you drag one onto the form. thanks!
  • 0

#6 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 26 April 2011 - 03:10 AM

you can display it in textbox...just write the code to display number on textbox every time after timer gets decrement
  • 0

#7 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 26 April 2011 - 05:25 AM


// Assuming you called your decrement variable "time_left"

// and your text box TextBox1.

TextBox1.Text = time_left.ToString();


  • -1

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#8 mitchel0

mitchel0

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 26 April 2011 - 11:33 AM

thansk you a lot!
  • 0





Also tagged with one or more of these keywords: timer, countdown

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download