Gets the total elapsed time measured by the current instance, in milliseconds. Gets the total elapsed time measured by the current instance. Indicates whether the timer is based on a high-resolution performance counter. Gets the frequency of the timer as the number of ticks per second. Initializes a new instance of the Stopwatch class. To specify processor affinity for a thread, use the ProcessThread.ProcessorAffinity method. However, because of bugs in the BIOS or the Hardware Abstraction Layer (HAL), you can get different timing results on different processors. On a multiprocessor computer, it does not matter which processor the thread runs on. Specifically, the Frequency field and GetTimestamp method can be used in place of the unmanaged Windows APIs QueryPerformanceFrequency and QueryPerformanceCounter. The Stopwatch class assists the manipulation of timing-related performance counters within managed code. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation. 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. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |