Power Apps Timer Control: From Countdown to Automation

The Timer Control in Power Apps is a versatile component that counts up or down for a specified duration.

It can trigger actions when it starts, pauses, or ends. This makes it useful for scenarios such as quizzes, countdowns, or recurring checks.

Basic Use Case: Quiz App

Imagine a quiz app where users have 5 seconds to answer each question.

Here’s how the Timer Control can be implemented:

  1. Insert a Timer Control from the Insert menu.
  2. Set the Duration property to 5000 (milliseconds = 5 seconds).
  3. Use the OnTimerStart property to create a variable: UpdateContext({ timerStatus: “started” })
  4. Use the OnTimerEnd property to update the same variable: UpdateContext({ timerStatus: “ended” })

Displaying Timer Status

Add a Label next to the timer to show its status.

Set the Text property using a Switch function:

Switch(
  timerStatus,
  "started", "Time is running",
  "ended", "Timer is up",
  ""
)
  

You can also change the Color property dynamically:

Switch(
  timerStatus,
  "started", RGBA(255,255,255,1), // White
  "ended", RGBA(255,0,0,1),       // Red
  RGBA(255,255,255,1)
)
  

Advanced Properties

  • Repeat: Restarts the timer automatically after ending. Useful for loops or recurring checks.
  • AutoStart: Starts the timer as soon as the app loads.
  • AutoPause: Pauses the timer when navigating away from the screen, preventing background execution.

Starting Timer with a Button

Instead of starting the timer directly clicking on it, you can trigger it with a button.

For example, in a Start Quiz button OnSelect property:

UpdateContext({ varTimerStart: true });
UpdateContext({ varQuestionVisible: true });
  

Then set:

  • Timer.Start = varTimerStart
  • OptionsContainer.Visible = varQuestionVisible

Navigation Example with AutoPause

If you add a Help button that navigates to another screen:

Navigate(HelpScreen)
  

With AutoPause set to On, the timer will stop when leaving the screen. If set to Off, the timer continues running in the background.

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *