xtd 0.2.0
Loading...
Searching...
No Matches

◆ stop()

void xtd::diagnostics::stopwatch::stop ( )
noexcept

Stops measuring elapsed time for an interval.

Remarks
In a typical xtd::diagnostics::stopwatch scenario, you call the xtd::diagnostics::stopwatch::start method, then eventually call the xtd::diagnostics::stopwatch::stop method, and then you check elapsed time using the xtd::diagnostics::stopwatch::elapsed property.
The xtd::diagnostics::stopwatch::stop method ends the current time interval measurement. stopping a xtd::diagnostics::stopwatch that is not running does not change the timer state or reset the elapsed time properties.
When a xtd::diagnostics::stopwatch instance measures more than one interval, the xtd::diagnostics::stopwatch::stop method is equivalent to pausing the elapsed time measurement. A subsequent call to xtd::diagnostics::stopwatch::start resumes measuring time from the current elapsed time value. Use the xtd::diagnostics::stopwatch::reset method to clear the cumulative elapsed time in a xtd::diagnostics::stopwatch instance.
Examples
The following example initializes a xtd::diagnostics::stopwatch instance by using a simple class constructor.
#include <xtd/diagnostics/stopwatch>
#include <xtd/threading/thread>
#include <xtd/console>
#include <chrono>
using namespace std::chrono;
using namespace xtd;
using namespace xtd::threading;
auto main() -> int {
thread::sleep(10000_ms);
// Get the elapsed time as a duration value.
auto ts = stopwatch.elapsed();
// Format and display the duration value.
auto elapsed_time = string::format("{0:H}:{0:M}:{0:S}.{1:D2}", ts, ts.milliseconds() / 10);
console::write_line("RunTime " + elapsed_time);
}
// This code produces the following output :
//
// RunTime 00:00:10.00
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
void stop() noexcept
Stops measuring elapsed time for an interval.
time_span elapsed() const noexcept
Gets the total elapsed time measured by the current instance.
void start() noexcept
Starts, or resumes, measuring elapsed time for an interval.
Provides a set of methods and properties that you can use to accurately measure elapsed time.
Definition stopwatch.h:36
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
lcd_label2.cpp.