c# - Environment.TickCount vs DateTime.Now -


is ever ok use environment.tickcountto 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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

How do you convert a timestamp into a datetime in python with the correct timezone? -