Click here to Skip to main content
15,913,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am going to evaluate a student by asking few questions.After clicks Start button I want to calculate how much time taken to answer these questions by the student.

there should be a fixed time allocated when starting the evaluation and it should be reduced(decrease)when time spending to answer the questions

what i want to display is :-
- how much time consume after clicking the start button
- Remaining time out of fixed time
Posted
Comments
[no name] 21-Aug-12 14:52pm    
Okay.... go right ahead and do that.
Nueman 21-Aug-12 14:56pm    
Looks like homework. I suggest you narrow down your question to a specific problem after you have exhausted efforts of your own. This is how you learn.

Use DateTime.Now to know the time they started. Then you can fire a timer regularly and subtract your stored value from DateTime.Now to find out how many seconds have passed.
 
Share this answer
 
Comments
ridoy 21-Aug-12 15:44pm    
good answer..+5
Sergey Alexandrovich Kryukov 21-Aug-12 18:41pm    
Well... for this purpose, System.Diagnostics.Stopwatch is used -- simpler, more straightforward for measuring and much better accuracy.
I put my answer, please see.
--SA
To calculate or just to measure? I think — to measure.

More accurate than System.DateTime is the class System.Diagnostics.Stopwatch:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx[^].

This is the best way to measure performance and related time interval values. The class documentation fully describes the use and the features.

—SA
 
Share this answer
 
Well basically you need to store just few pieces of information
  • The time the person started to answer questions
  • The fixed amount of time that's given to answer the question

To get the current time, you can use DateTime.Now[^] property. Using this property you can record the time when answering started and you can also use it when you calculate how much time has been elapsed. To get the remaining time you just subtract the elapsed time from the allowed time.

In order to update your UI to show the remaining time you can use timer as already said or an instance of a BackgroundWorker[^] class.

Just remember that you cannot update your UI from another thread so you need to check that the calling thread is the same as the UI thread. In order to do this, you can use the CheckAccess[^] method of the Dispatcher.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Aug-12 18:41pm    
Well... for this purpose, System.Diagnostics.Stopwatch is used -- simpler, more straightforward for measuring and much better accuracy.
I put my answer, please see.
--SA
Wendelius 22-Aug-12 0:18am    
That's true, stopwatch would be appropriate. :)
Not too many codes to do it..the answer of Christian Graus is absolutely right..i add a little bit with it.Set timer for your application..and increase it for every second in timer_tick event.I mean second++..By it you will measure how much time taken to answer question,then as mentioned earlier by Christian Graus,subtract it from fixed time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900