cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dzemiol
Level: Powered On

Is OnStart code of first window executed before OnVisible of the same window

Hi,

 I came across following issue. I have a pretty big OnStart section where many global variables are set. When I start using them in OnVisible section I have cases that some of them are not yet set. Are OnStart and On Visible executed in parallel or sequencially. Is there a way to make sure that OnStart is fully executed before OnVisible of first window starts running?

Thanks for help
Marcin Jemiol


Accepted Solutions
o365masters
Level: Powered On

Re: Is OnStart code of first window executed before OnVisible of the same window

I’ve also used a Timer control to ensure all the steps in the OnStart property have completed before other functions I want to call run.

Generally I set a variable as one of the first steps in the OnStart, something like:
Set( background_timer_v, false );

Then for the final step in the OnStart:
Set( background_timer_v, true )

I generally then avoid putting anything in the OnVisible property for the Home screen at least.

For the “Background_Timer” control in the Start and AutoStart properties I set the values to:
“background_timer_v”

Finally in the OnStart property of the Timer control for the last step:
Set( background_timer_v, false )
to ensure it doesn’t run again.

It might be a bit more tricky if you “do” want that code to run each time the user navigates back to the home page, in which case I wouldn’t reset the status of the background_timer_v back to false, but instead on the:
OnVisible property add:
UpdateContext( { page_visible: true })
OnHidden property add:
UpdateContext( { page_visible: false })

And the on the Start & AutoStart properties of the Background_Timer control insert:
background_timer_v && page_visible_v

Also set the timer Repeat property to false

All Replies
Super User Rank
Super User

Re: Is OnStart code of first window executed before OnVisible of the same window

Hi @dzemiol,

You could use a timer control in the OnVisible property to set a delay for a fixed time or when an event at the end of the functions in the OnStart property fires.  For more information regarding the Timer control see canvas-apps/controls/control-timer

o365masters
Level: Powered On

Re: Is OnStart code of first window executed before OnVisible of the same window

I’ve also used a Timer control to ensure all the steps in the OnStart property have completed before other functions I want to call run.

Generally I set a variable as one of the first steps in the OnStart, something like:
Set( background_timer_v, false );

Then for the final step in the OnStart:
Set( background_timer_v, true )

I generally then avoid putting anything in the OnVisible property for the Home screen at least.

For the “Background_Timer” control in the Start and AutoStart properties I set the values to:
“background_timer_v”

Finally in the OnStart property of the Timer control for the last step:
Set( background_timer_v, false )
to ensure it doesn’t run again.

It might be a bit more tricky if you “do” want that code to run each time the user navigates back to the home page, in which case I wouldn’t reset the status of the background_timer_v back to false, but instead on the:
OnVisible property add:
UpdateContext( { page_visible: true })
OnHidden property add:
UpdateContext( { page_visible: false })

And the on the Start & AutoStart properties of the Background_Timer control insert:
background_timer_v && page_visible_v

Also set the timer Repeat property to false