Skip to content
April 12, 2010 / kiranpatils

How to use System.Diagnostics.Stopwatch?

Stopwatch is a good guy provided by MS to accurately measure elapsed time.


System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();

// Your Time Consuming Code goes here..

stopWatch.Stop();

// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;

// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);

Happy Coding! 🙂

Advertisement

2 Comments

Leave a Comment
  1. aspen / Apr 13 2010 2:39 am

    Не получается скормить ваш rss читалке Abilon. Точнее могу, но читать не получается – прога по ходу не может получить новости. Пытаюсь добавить эту ленту – https://kiranpatils.wordpress.com/feed/. Подскажите придурку – кто чем читает kiranpatils.wordpress.com?

  2. Juan Pablo / Oct 1 2012 7:01 pm

    With the overload of ToString method in .NET 4, you can parse with ease to mm:ss.fff

    Here is an example

    http://methodsoftware.blogspot.com.es/2012/10/stopwatch-of-systemdiagnostics.html

    Greetings!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: