Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
259a4542
Commit
259a4542
authored
Nov 18, 2012
by
Davis King
Browse files
Simplified example
parent
3740c16b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
23 deletions
+18
-23
examples/timer_ex.cpp
examples/timer_ex.cpp
+18
-23
No files found.
examples/timer_ex.cpp
View file @
259a4542
...
...
@@ -2,10 +2,10 @@
/*
This is an example illustrating the use of the timer object.
This is an example illustrating the use of the timer object
from the dlib C++ Library
.
The timer
object
is an object that calls some user specified member function
in
its own thread at regular intervals
.
The timer is an object that calls some user specified member function
at regular
in
tervals from another thread
.
*/
...
...
@@ -21,25 +21,6 @@ using namespace std;
class
timer_example
{
public:
timer_example
(
)
:
// Here we construct our timer object. It needs two things. The second argument is
// the member function it is going to call at regular intervals and the first
// argument is the object instance it will call that member function on.
t
(
*
this
,
&
timer_example
::
action_function
)
{
// set the timer object to trigger every second
t
.
set_delay_time
(
1000
);
// start the timer. It will start calling the action function
// 1 second from this call to start.
t
.
start
();
}
private:
timer
<
timer_example
>
t
;
void
action_function
()
{
// print out a message so we can see that this function is being triggered
...
...
@@ -53,8 +34,22 @@ int main()
{
timer_example
e
;
// sleep for 10 seconds before letting the program end
// Here we construct our timer object. It needs two things. The second argument is
// the member function it is going to call at regular intervals and the first argument
// is the object instance it will call that member function on.
timer
<
timer_example
>
t
(
e
,
&
timer_example
::
action_function
);
// Set the timer object to trigger every second
t
.
set_delay_time
(
1000
);
// Start the timer. It will start calling the action function 1 second from this call
// to start.
t
.
start
();
// Sleep for 10 seconds before letting the program end.
dlib
::
sleep
(
10000
);
// The timer will destruct itself properly and stop calling the action_function.
}
// ----------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment