2nd Panel not showing at normal speed

enonod

Well-Known Member
Licensed User
Longtime User
If the following, which is in Button_click, is run under debug stepping the 2nd panel shows correctly proving it works.
At normal debug running the first panel remains until the end of file transaction and then the 2nd panel flashes quickly.
The second panel is called at Commom...
Any clues please?
B4X:
      pCommon.RemoveView
            If Player.Name="" Then
               Player.Name=etName.text
            End If
            Common("Message","MESSAGE","Saving Your Game",1,"","")
            If Not (File.Exists(File.DirInternal,Player.Name&Player.Clrs&".dat")) Then
               lGames.Add(Player)
               WriteGames   
            End If
            raf.Initialize(File.DirInternal,Player.Name&Player.Clrs&".dat",False)
            raf.WriteObject(Player,True,raf.CurrentPosition)
            raf.WriteObject(aGrid,True,raf.CurrentPosition)
            raf.WriteObject(lUndo,True,raf.CurrentPosition)
            raf.WriteInt(Player.Clrs,raf.CurrentPosition)
            raf.Close   
            pCommon.RemoveView
            Activity.Finish
 

stevel05

Expert
Licensed User
Longtime User
Try adding DoEvents after the RemoveView
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you. I did that and yes the first panel did immediately disappear but the second did not appear.
I then put Do Events after the 'Common...' and everything did work fine.
I should like to know how to determine when to do this because I have similar panels throughout my program and have never had a problem, only with this one where one is removed before the second appears... but the Do Evenets is required for the second... where there appears to be plenty of time to appear.

Any help in understanding this will be appreciated.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Do Events is needed when you want the system to look at doing something with the UI when it would otherwise be busy running other code. In your case, when you ask it to remove the view and draw a new one it immediately gets on with writing the file, once that is finished it draws the new view just before exiting.

Adding DoEvents requests that the system does it sooner.

As an example, you may have a loop that does processing and updates a progress bar, if you don't call DoEvents within the loop ,the progress bar will not be updated until the process loop exits and the system has time to update it.
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you stevel05.
 
Upvote 0
Top