Since adding a second timer to my widget app, I’ve noticed an issue in the simulator: after each call to onUpdate in my view, there’s a 2-3 second delay before any other queued events (timers, user input, web responses) are processed.
If I disable (comment out) either of the two main timers, the delay disappears.
To investigate further, I added a third timer inside onUpdate that triggers a one-time callback after 50ms. This third timer doesn’t appear to contribute to the issue, the original delay still occurs only if both main timers are active.
public function onUpdate( dc as Dc ) as Void {
EvccHelperBase.debug("WidgetSiteBase: onUpdate" );
// Some drawing
EvccHelperBase.debug( "WidgetSiteBase: onUpdate completed" );
_updateCounter++;
if( _updateCounter > 2 ) {
var timer = new Toybox.Timer.Timer();
timer.start( method( :testTimer ), 50, false );
}
}
private var _updateCounter as Number = 0;
public function testTimer() as Void {
EvccHelperBase.debug( "WidgetSiteBase: timer triggered" );
}
The test timer is used solely to ensure that a timer event is queued immediately after onUpdate completes. A counter is necessary because, during startup, I can only instantiate two timers -attempting to create a third results in an error. However, after the startup phase, I’m able to instantiate the third timer without any issues.
Here’s the log file that demonstrates the problem:
12.4.2025 17:21:42: TaskQueue: timer triggered
12.4.2025 17:21:42: TaskQueue: timer triggered
12.4.2025 17:21:42: WidgetSiteBase: onUpdate
12.4.2025 17:21:42: WidgetSiteBase: onUpdate completed
12.4.2025 17:21:44: TaskQueue: timer triggered
12.4.2025 17:21:44: WidgetSiteBase: timer triggered
12.4.2025 17:21:44: TaskQueue: timer triggered
12.4.2025 17:21:44: TaskQueue: timer triggered
12.4.2025 17:21:44: TaskQueue: timer triggered
12.4.2025 17:21:44: TaskQueue: timer triggered
12.4.2025 17:21:44: TaskQueue: timer triggered
12.4.2025 17:21:45: MultiStateRequestsTimer: timer triggered
12.4.2025 17:21:46: StateRequest: onReceive
You can see the gap between the end of onUpdate at 17:21:42 and the first timer event that follows at 17:21:44. Another timer appears to be slipping in between onUpdate and the test timer.
All my event handlers include debug output, so I’m confident that none of my code is being executed during that two-second delay.
The first of the two main timers is initialized as follows - it’s responsible for performing regular web requests:
public class EvccMultiStateRequestsHandler {
private var _timer as Timer.Timer = new Timer.Timer();
public function startRequestTimer() as Void {
_timer.start( method( :makeRequest ), 5000, true );
}
public function makeRequest() as Void {
//...
}
}
The second timer handles a queue of tasks and is set up like this:
class EvccTaskQueue {
private static var _instance as EvccTaskQueue?;
public static function getInstance() as EvccTaskQueue {
if( _instance == null ) { _instance = new EvccTaskQueue(); }
return _instance as EvccTaskQueue;
}
private function initialize() {}
private var _timer as Timer.Timer = new Timer.Timer();
private function startTimer() as Void {
_timer.start( method( :executeTask ), 50, false );
}
public function executeTask() as Void {
// ...
startTimer();
}
}
Both code snippets are simplified, but they should capture the essence of what’s going on.
Does anyone have an idea what in my code might be causing the delay after onUpdate, and how it could be related to the two timers?