Jump to content

Timing.

- - - - -

  • Please log in to reply
3 replies to this topic

#1
AIGuy

AIGuy

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
I'm trying to find some way to start a timer in code, and then check back at some point to see how long it's been running for (in milliseconds preferably). The purpose of this is:

There will be two instances of this program on two networked computers. On a signal they will first sync there timers and then display a question on the screen. As soon as the user on the local computer submits acceptable input, his timer will be stopped. After both inputs are in, the times will be compared to determine who answered first.

If there is a better way to do this please let me know. If you know how to "set a stop watch" that would be great too.

#2
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
x.Interval = 1000; //Meaning 1 second
x.Start();

//each 1000 milliseconds or 1 second, the Tick function will be called
//double-click your timer in the designer window to make it appear in your code
int time = 0;

private void MyTimer_Tick(...something here...)
{
     time++;
}
Ask me if you have any questions.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#3
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
I think you'll be better off using the Stopwatch class, rather than a form timer (as suggested above). You'll want to look at the Start, Stop, ElapsedMilliseconds, and Reset methods/properties.

#4
AIGuy

AIGuy

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
Thanks Monerath. Your idea was good too Davide, just wasn't precise enough. :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users