Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-10

Most efficient way for polling (TTimer, OnIdle, TIdleTimer, TThread)

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luiz Americo Pereira Camara

I have a component that needs to poll a SimpleIPC server repeatedly (at each 1s or so).

Currently i'm using a TTimer with a OnTimer handler that calls FIPCServer.PeekMessage(1, True);.

Wondering if using TIdleTimer, Application.OnIdle(or AddIdleHandler) or a separated TThread will be more efficient.

By efficiency i mean low resource usage, notebook battery friendly

Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20161013/29d5d5a1/attachment.html>

Reply by email

Michael Schnell
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote
I have a component that needs to poll a SimpleIPC server repeatedly (at each 1s or so).

While I do think that polling once a second will not do any noticeable harm, a better design might be to push some kind of message from the other site and wait for same in a function that does an appropriate OS call.

(E.g a TThread doing a blocking wait for a pipe and then using TThread.Queue to call an event handler function in the main thread.)

-Michael

Reply by email