Is it ever OK to use Environment.TickCount to calculate time spans?
int start = Environment.TickCount; // Do stuff int duration = Environment.TickCount - start; Console.WriteLine("That took " + duration " ms");
Because TickCount is signed and will rollover after 25 days (it takes 50 days to hit all 32 bits, but you have to scrap the signed bit if you want to make any sense of the math), it seems like it’s too risky to be useful.
I’m using DateTime.Now instead. Is this the best way to do this?
DateTime start = DateTime.Now; // Do stuff TimeSpan duration = DateTime.Now - start; Console.WriteLine("That took " + duration.TotalMilliseconds + " ms");
Use the Stopwatch class. There is a decent example on MSDN: Stopwatch Class