' Service Module: TimerService
Sub Process_Globals
Private timer1 As Timer
Private RunDurationMillis As Long = 60 * 1000 ' Run for 1 minute
Private RestDurationMillis As Long = 6 * 60 * 1000 ' Wait/restart after 6 minutes
Private fgNotifID As Int = 51042 'datasync
End Sub
Sub Service_Create
timer1.Initialize("timer1", RunDurationMillis) ' 1 minute active period
End Sub
Sub Service_Start(StartingIntent As Intent)
StartForeground
timer1.Enabled = True
End Sub
Sub StartForeground
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo("1-Minute Worker", "Working for 1 minute...", Main)
Service.StartForeground(fgNotifID, n)
End Sub
Sub timer1_Tick
DoWorkLoop
timer1.Enabled = False
Service.StopForeground(fgNotifID)
StopService("")
ScheduleNextRun
End Sub
Sub DoWorkLoop
' Put your actual work here - usually a for loop or work tasks
For i = 1 To 100
Log($"Do work step ${i}"$)
Sleep(100) ' Simulate processing per step
Next
End Sub
Sub ScheduleNextRun
Dim nextRun As Long = DateTime.Now + RestDurationMillis
StartServiceAtExact("TimerService", nextRun, True)
Log($"Scheduled service to run again at: ${DateTime.Time(nextRun)}"$)
End Sub
Sub Service_Destroy
timer1.Enabled = False
Service.StopForeground(fgNotifID)
End Sub