How to measure elapsed time in C# with StopWatch

By Emanuele Bartolesi at March 20, 2009 04:50
Filed Under: Asp.net, C#

StopWatch class can measure elapsed time for one interval.
We can use for measuring performance of the new code blocks or algorithms. Use IsRunning method to determine the state of StopWatch object.
Use Start method to begin measuring elapsed time, and Stop method to stop measuring elapsed time.

{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
textBox1.Text = DateTime.Now.TimeOfDay.ToString();
Application.DoEvents();

// Perform a long process
Thread.Sleep(34564);

stopwatch.Stop();
textBox2.Text = DateTime.Now.TimeOfDay.ToString();
textBox3.Text = stopwatch.Elapsed.Milliseconds.ToString();
Application.DoEvents();
}

Comments

10/8/2009 11:51:56 AM #

Pleased I chanced upon this how to post.  How to measure elapsed time in C with  - I have been searching for opinions on how to take on this at the present moment  and got drawn by the title of the posting in Yahoo.  Reading text books and papers has not been advantageous but a couple of web lookups has brought about a result which should help me a lot.  How could we live without the Internet.  Thank you, I will use the data and must keep your internet site as a source.

Soakaway United Kingdom

10/15/2009 12:57:47 AM #

Interesting ... as always - is your blog making any cash advance ? ;)

cash advance United States

11/27/2009 10:58:49 AM #

Nice post. Bookmarked it already. have a nice day, John.

games free

About me

I will also give you some useful tips, based on the modest wisdom gained during the years that I've worked as a developer and project manager.

Widget

Ohloh profile for Emanuele Bartolesi

 

Wakoopa

Software tracking

 

Software tracking

from Amazon



hacker emblem



Scarica il pdf di Game
Rivista Game di videogiochi
Trucchi videogiochi