xtd 0.2.0
timer.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "component.hpp"
6#include <xtd/chrono>
7#include <xtd/event>
8#include <xtd/event_handler>
9#include <xtd/time_span>
10#include <cstdint>
11#include <memory>
12
14namespace xtd {
16 namespace forms {
38 class forms_export_ timer : public component {
39 struct data;
40
41 public:
43
50
52 timer(timer&&) = default;
53 timer(const timer&) = delete;
54 ~timer();
56
58
63 virtual bool enabled() const noexcept;
67 virtual timer& enabled(bool enabled);
68
71 virtual time_span interval() const noexcept;
75
79 virtual int32 interval_milliseconds() const noexcept;
85
87
91 void start();
92
95 void stop();
97
99
103 static timer create();
112 static timer create(const time_span& interval, bool enable);
121 static timer create(int interval_milliseconds, bool enable);
123
125
132
133 protected:
135
139 virtual void on_tick(const event_args& e);
141
142 private:
143 void restart();
144
145 xtd::sptr<data> data_;
146 };
147 }
148}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Represents an event.
Definition event.hpp:21
component()
Initialises a new instance of the component class.
virtual time_span interval() const noexcept
Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of th...
virtual bool enabled() const noexcept
Gets whether the timer is running.
static timer create()
A factory to create an xtd::forms::timer.
timer()
Initializes a new instance of the timer class.
void stop()
Starts the timer.
virtual int32 interval_milliseconds() const noexcept
Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of th...
virtual void on_tick(const event_args &e)
Raises the xtd::forms::timer::tick event.
void start()
Stops the timer.
event< timer, event_handler > tick
Occurs when the specified timer interval has elapsed and the timer is enabled.
Definition timer.hpp:130
Represents a time interval.
Definition time_span.hpp:29
Contains xtd::forms::component class.
generic_event_handler< const xtd::event_args & > event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.hpp:24
#define forms_export_
Define shared library export.
Definition forms_export.hpp:13
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
@ e
The E key.
Definition keys.hpp:207
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201