[fpc-pascal] Daemon using TTimer on Windows

R0b0t1 r030t1 at gmail.com
Sun Jul 1 02:13:26 CEST 2018


On Sat, Jun 30, 2018 at 3:57 PM, Marcos Douglas B. Santos
<md at delfire.net> wrote:
> Hi,
>
> I need to build a daemon app on Windows. It will need a timer to
> performe some tasks. This timer could be big among 15 min, 30 min, 2
> hours, etc.
>
> I thought that I can use TTimer but I've always heard that it's not
> possible because some problems related with "NoGUI" stuff.
>
> I've found a thread[1] which talks about that but they haven't
> provided a real solution, at least for Windows.
>
> My question is: Nowadays, can I use TTimer with no restrictions in a
> daemon application on Windows? If not, which could be a possible
> solution?
>

If all your service does is wait for the timer you should instead use
a scheduled task.

Anyway - does TTimer use the WM_TIMER message? That is the type tied
to the GUI. Even if you need to use WM_TIMER for some reason you can,
as services should be run in "session 0" and should have access to a
GUI. The latter is, I think, a compatibility option you can enable.

If you are not opposed to OS-level primitives you should use waitable
timers (https://docs.microsoft.com/en-us/windows/desktop/sync/using-waitable-timer-objects).
Using waitable timers you can also wake the computer from sleep.

Cheers,
     R0b0t1



More information about the fpc-pascal mailing list