The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Another useful class
I am probably the last person to discover this but only today I discovered the Stopwatch type in the System.Diagnostics namespace. Real nice when you want to determine how long a certain action took Smile
 
Stopwatch timer = Stopwatch.StartNew();
timer.Start();
// Do some stuff you want to time.
timer.Stop();
Console.WriteLine(timer.Elapsed.ToString());
 
Use the Stopwatch.IsHighResolution to check if the timer is using high resolution of not.
 
Enjoy!
 
Published Mon, Jan 15 2007 16:19 by Maurice
Filed under:

Comments

# re: Another useful class@ Thursday, January 18, 2007 9:14 AM

here is how to format elapsed in hh:mm:ss:mmm

Dim ts As TimeSpan = timer.Elapsed

Dim timeElapsed As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _

               ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)

by Jim

# re: Another useful class@ Saturday, January 20, 2007 7:19 AM

Unless I am very mistaken that is the default formatting of a TimeSpan.ToString().

by Maurice