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

◆ start()

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

Starts, or resumes, 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.
Once started, a xtd::diagnostics::stopwatch timer measures the current interval, in elapsed timer ticks, until the instance is stopped or reset. starting a xtd::diagnostics::stopwatch that is already running does not change the timer state or reset the elapsed time properties.
When a stopwatch instance measures more than one interval, the start method resumes measuring time from the current elapsed time value. A stopwatch instance calculates and retains the cumulative elapsed time across multiple time intervals, until the instance is reset. Use the reset method before calling start to clear the cumulative elapsed time in a stopwatch instance. Use the restart method to reset and start the stopwatch with a single command.
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, and stopwatch_constructor.cpp.