c# - Environment.TickCount vs DateTime.Now -
is ever ok use environment.tickcount
to calculate time spans?
int start = environment.tickcount; // stuff int duration = environment.tickcount - start; console.writeline("that took " + duration " ms");
because tickcount
signed , rollover after 25 days (it takes 50 days hit 32 bits, have scrap signed bit if want make sense of math), seems it's risky useful.
i'm using datetime.now
instead. best way this?
datetime start = datetime.now; // stuff timespan duration = datetime.now - start; console.writeline("that took " + duration.totalmilliseconds + " ms");
use stopwatch class. there decent example on msdn: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx
stopwatch stopwatch = stopwatch.startnew(); thread.sleep(10000); stopwatch.stop(); // elapsed time timespan value. timespan ts = stopwatch.elapsed;
Comments
Post a Comment