subs
subs

Reputation: 2249

How to schedule a task in C++

I have a C++ windows service which should call a function every 15 minutes. I am new to c++ and have no idea how to do this.Can anybody tell me how to achieve this?

Thanks, Subrat

Upvotes: 3

Views: 13786

Answers (3)

Nate
Nate

Reputation: 19030

Call SetTimer().

Alternately, use the Task Scheduler API, which can execute a regular .exe or COM handler on a predefined schedule. If you do that, you may not even need a service.

Upvotes: 5

peoro
peoro

Reputation: 26060

There are many libraries to provid timers.

What operating system and what libraries are you using? You could implement one by yourself using Boost::Timer (or even standard C time-related functions from ctime header), or, if you're using a library that handles the main loop, it for sure provides some functions.

Upvotes: 4

Armen Tsirunyan
Armen Tsirunyan

Reputation: 132984

There is <ctime> header in C++ (<time.h> in C) which provides some basic low-level time functionality. However if you are seeking something more close to c#'s timer then you can use Qt's QTimer class. Get to know Qt - it's a good thing.

Upvotes: 1

Related Questions