You are not logged in.
Pages: 1
Hello,
Can anybody please share an example on how to use TimerEnable / TimerDisable? I cannot find any example or documentation about it. The commentary on the source code says the following:
Define a task running on a periodic number of seconds in a background thread
could be used to run background maintenance or monitoring tasks on this TSQLRest instance, at a low pace (typically every few minutes)
will instantiate and run a shared TSynBackgroundTimer instance for this TSQLRest, so all tasks will share the very same thread
you can run BackgroundTimer.EnQueue or ExecuteNow methods to implement a FIFO queue, or force immediate execution of the process
will call BeginCurrentThread/EndCurrentThread as expected e.g. by logs
But no mention on how to actually use it. Any example on how to use it?
Last edited by leus (2020-12-10 14:51:18)
Offline
That's the question.
Offline
I use it in a small application as follows:
procedure TDWSRestServer.DownloadDWData(pmSender: TSynBackgroundTimer; pmEvent: TWaitResult; const pmcMsg: RawUTF8);
const
URL_TEMPLATE = 'https://...';
var
log: ISynLog;
url: SockString;
content: SockString;
begin
log := LogClass.Enter(Self, 'DownloadDWData');
with FRestServiceSettings do
url := StringToAnsi7(FormatString(URL_TEMPLATE, [DWUserName, DWUserPassword, DWUserAPIToken]));
content := HttpGet(url);
...
end;
procedure TDWSRestServer.Start;
var
timer: TSynBackgroundTimer;
begin
timer := TimerEnable(DownloadDWData, FRestServiceSettings.DataUpdateInterval);
if Assigned(timer) then
timer.ExecuteNow(DownloadDWData);
end;
procedure TDWSRestServer.Stop;
begin
TimerDisable(DownloadDWData);
end;
With best regards
Thomas
Offline
I did this, because my task lives inside my service (not in the server). Is this right?
someService := T.Create();
aRestServer.ServiceDefine(someService, [ISomeService]);
aRestServer.TimerEnable(someService.MyBackgroundTask, 360);
Last edited by leus (2020-12-10 16:50:35)
Offline
I have some inquiries regarding this previous thread:
Does a TSynBackgroundTimer utilize a thread to sequentially execute aOnProcess: TOnSynBackgroundTimerProcess?
How can I employ separate threads to execute multiple tasks concurrently in the background? Is it possible to use multiple TSynBackgroundTimer instances for this purpose?
Would you please provide me with more examples?
Offline
Pages: 1