And yes, on your game server thread use Sleep(1) if you want to be nice to the CPU. But you don't have to.
using System;using System.ComponentModel;using System.Diagnostics;using System.Threading;using System.Windows.Forms;//----------------------------------------------------------------// TimeManager - gives time elapsed in ms since last server tick// How to use: - call TimeManager.Initialize() on startup// - call TimeManager.Update() in your Update function// - TimeManager.timeElapsed is time elapsed since last tick //----------------------------------------------------------------public static class TimeManager{ // the time elapsed since the previous server tick public static float timeElapsed; // the StopWatch and private variables private static Stopwatch stopWatch; private static float currentTime; private static float oldTime; //---------------------------------------------------------------- // Initialize() - call once on program start //---------------------------------------------------------------- public static void Initialize() { stopWatch = new Stopwatch(); stopWatch.Reset(); stopWatch.Start(); } //---------------------------------------------------------------- // Update() - calculates ms elapsed since last server tick //---------------------------------------------------------------- public static void Update() { // save previous time // update current time // calculate time elapsed in ms oldTime = currentTime; currentTime = (float)stopWatch.ElapsedMilliseconds; timeElapsed = currentTime - oldTime; } //---------------------------------------------------------------- // Reset() - reset stopwatch to 0 //---------------------------------------------------------------- public static void Reset() { stopWatch.Reset(); stopWatch.Start(); oldTime = (float)stopWatch.ElapsedMilliseconds; currentTime = (float)stopWatch.ElapsedMilliseconds; }}