Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I call Stop before reading ElapsedMilliseconds?

Tags:

c#

stopwatch

Can I get the elapsed time since I have called Start on a stopwatch using ElapsedMilliseconds without calling Stop? I have searched a lot round the internet but only saw examples where ElapsedMilliseconds is called after Stop. Is this value filled on a call to Stop or is it always correct?

like image 510
Ivaylo Strandjev Avatar asked Mar 30 '13 16:03

Ivaylo Strandjev


People also ask

What is elapsed milliseconds?

ElapsedMilliseconds. Returns the number of milliseconds that have elapsed since a specific time in the past.

What is elapsed time in Stopwatch?

By default, the elapsed time value of a Stopwatch instance equals the total of all measured time intervals. Each call to Start begins counting at the cumulative elapsed time; each call to Stop ends the current interval measurement and freezes the cumulative elapsed time value.

What is use of Stopwatch in C#?

Stopwatch is a class in C# to measure the elapsed time. Use it to calculate the time a function took to execute. It is found under System.

What is tick Stopwatch?

A tick is the smallest unit of time that the Stopwatch timer can measure. Use the Frequency field to convert the ElapsedTicks value into a number of seconds.


1 Answers

You can query the properties Elapsed, ElapsedMilliseconds, and ElapsedTicks while the Stopwatch instance is running or stopped. The elapsed time properties steadily increase while the Stopwatch is running; they remain constant when the instance is stopped.

— From https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch.elapsedmilliseconds#remarks

like image 166
Rob G Avatar answered Oct 16 '22 19:10

Rob G