Otherwise, the Stopwatch class uses the system timer to measure elapsed time. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. Use the Reset method to clear the cumulative elapsed time in an existing Stopwatch instance. 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. The elapsed time properties steadily increase while the Stopwatch is running they remain constant when the instance is stopped.īy default, the elapsed time value of a Stopwatch instance equals the total of all measured time intervals. You can query the elapsed time properties while the instance is running or stopped. Query the elapsed time value through the properties Elapsed, ElapsedMilliseconds, or ElapsedTicks. Use Start to begin measuring elapsed time use Stop to stop measuring elapsed time. In a typical Stopwatch scenario, you call the Start method, then eventually call the Stop method, and then you check elapsed time using the Elapsed property.Ī Stopwatch instance is either running or stopped use IsRunning to determine the current state of a Stopwatch. String elapsedTime = String.Format(" milliseconds", _Ī Stopwatch instance can measure elapsed time for one interval, or the total of elapsed time across multiple intervals. ![]() Format and display the TimeSpan value. Get the elapsed time as a TimeSpan value. The following example demonstrates how to use the Stopwatch class to determine the execution time for an application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |