Power Community

Power Community

Timing issues in relation to App OnStart, Screen OnVisible, Timers and user interruptions in Power Apps

Timing issues in relation to App OnStart, Screen OnVisible, Timers and user interruptions in Power Apps Microsoft Office 365 timing

When you create apps, it is important to understand the timing issues that may happen. When various elements manipulate data, things could go wrong quite easily. fixing these issues however is not an easy task.

Running code

When you create an app there are various places where you can insert code to read data or write data.

We can add code in the following places:

  • App OnStart
  • Screen OnVisible
  • Timer ( On Start and On End)
  • User clickable controls such as a button.
Timing issues in relation to App OnStart, Screen OnVisible, Timers and user interruptions in Power Apps

Any of the above pieces of code could conflict with each other. This means that we cannot guarantee that one has finished before the following is executed when we play the app.

Execution order

To test the order or things I created the above app and made the app OnStart, Screen OnVisible and the Timer sets a variable then call flow that waits 10 seconds and then set another variable.

Using the above tests I also redirected my app to a second screen before any of the code completed.

Timing issues in relation to App OnStart, Screen OnVisible, Timers and user interruptions in Power Apps Microsoft Office 365 image 13

From the above Start and End timings of each of the pieces of code we can see that

The App On Start is started first, then the Timer on Screen 1 before the Screen OnVisible is started.

On the second screen the Timer 2 is also started before the Screen 2’s OnVisble code is run.

The important thing to notice here is that a Screen’s On Visible code is only called once all the elements on the screen have been loaded.

Completion of code

In my test I configured a few different waiting times as shown in the below table.

Code SectionWait time in flowDifference between start and end
App OnStart1011
Screen 1 OnVisible1012
Timer Screen 112
Screen 2 OnVisible56
Timer Screen 256

As we can see each piece of code is running for the period of time that my flow is waiting with, as expected, a bit of overhead.

When I start my app, we can see the order in which each piece of code completes.

On the first screen I even included a button for a user to interrupt the process. Or maybe I should say not interrupt the process as the various code block will still run in the same order all at the same time. This running of code in an asynchronous way can of course cause major issues.

If your second screen in the app expects runs OnVisible code that expects the OnStart code to have been completed. Then you might run into some errors.

Protecting your apps

So what do we do to avoid these kind of issues? You could like I did in my app set variables at the end of your code blocks. Any code then relying on other code blocks to have run, will then have to wait until that variable has been set.

This way we could for example disable Timers or buttons until the OnVisible or OnStart code has completed.

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Is your Asynchronous plugin or Workflow not running in Dataverse?

Implementation Steps: 1. Navigate to https://admin.powerplatform.microsoft.com/ 2. Click on Environments 3. Open the Environment where you want to run your plugins or workflows 4....

More Articles Like This

- Advertisement -spot_img