|
-
Sep 9th, 2007, 08:38 AM
#1
Thread Starter
Addicted Member
Timer Question
I would like to know how to get my timer to begin counting the elapsed time. Sort of like a stop watch. I don't want it displaying the time of day, just starting from 0, and going to 20 minutes.
We have an application for our business center machine, and we want a small window on the desktop that will count the elapsed time the software is allowing them to use the machine before log off.
-
Sep 9th, 2007, 08:47 AM
#2
Re: Timer Question
Create a TimeSpan containing 20 minutes.
Create a Stopwatch and Start it.
Create a Timer and Start it.
In the timer's Tick event handler subtract the Stopwatch's Elapsed time from the 20 minute TimeSpan and that's the time you have left. You can display that value in a Label or whatever.
-
Sep 9th, 2007, 08:49 AM
#3
Hyperactive Member
Re: Timer Question
What do you mean by Stop Watch? I thought you could only get timers!
------
KNXRB
-
Sep 9th, 2007, 09:00 AM
#4
Re: Timer Question
By Stopwatch I mean an instance of the Stopwatch class. It's not a component like a Timer, so you create it in code. A Stopwatch doesn't actually do anything while it's Running. It simply remembers the current time when you Start it. Each time you get its Elapsed property it simply subtracts that start time from the current time to get the elapsed time. See this thread for a similar implementation designed for .NET 1.x, before the Stopwatch class was added to the Framework.
By the way, whenever I say "create a Thing" you can assume that I mean "create an instance of the Thing class", whatever "Thing" might be. I always use the proper names for types and members, including character casing. I think it's worth spending a few seconds more to post clearly.
Last edited by jmcilhinney; Sep 9th, 2007 at 09:05 AM.
-
Sep 9th, 2007, 10:48 AM
#5
Hyperactive Member
-
Sep 9th, 2007, 11:29 AM
#6
Thread Starter
Addicted Member
Re: Timer Question
That helped, but I do not know how to implement the code. I can not figure out how to get the timer to start. Where do I put each section of code?
-
Sep 9th, 2007, 05:59 PM
#7
Re: Timer Question
Have you read the documentation for the Timer class?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|