B4J Question Only one Wait For works

jroriz

Active Member
Licensed User
Longtime User
In the code below (also attached), only one WAIT FOR call works.

If I call the first one, the second one doesn't work, the program just closes without any message.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Dim sp As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)


    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    
    ' if I call liberar after showsplashscreen, the programa closes without any message...
    Wait For (ShowSplashScreen) complete  (r As Object)
    
    ' if I call showsplashscreen and liberar,  the programa closes without any message...
    ' if I call liberar without calling showsplashscreen, liberar works
    Wait For (liberar) complete (r As Object)

    Log("liberado")
    
    MainForm.Show
End Sub

Sub liberar As ResumableSub

    Dim sisweb As HttpJob
    sisweb.Initialize("", Me)

    sisweb.Download("https://sisweb.app/pix/validar/chaves.txt")

    Wait For (sisweb) JobDone(sisweb As HttpJob)

    If sisweb.Success Then
        Log("chaves ok")
    Else
        xui.MsgboxAsync("Servidor inacessível. Verifique sua conexão", "SERVIDOR")    ' sisweb.app inacessivel
        ExitApplication
    End If

    sisweb.Release
    
    Return Null
End Sub

Sub ShowSplashScreen As ResumableSub
    sp.Initialize("sp", 271, 153)

    sp.SetFormStyle("TRANSPARENT")
    sp.BackColor = fx.Colors.Transparent
    CSSUtils.SetBackgroundImage(sp.RootPane, File.DirAssets, "splash.png")
    sp.Show
    sp.RootPane.Alpha = 0
    sp.RootPane.SetAlphaAnimated(500, 1)
    Wait For (sp.RootPane) sp_AnimationCompleted
    
'    func.Initialize

    'Wait For (liberar) complete (r As Object)
    
    Sleep(2000)

    sp.RootPane.SetAlphaAnimated(1000, 0)
    Wait For (sp.RootPane) sp_AnimationCompleted
    sp.Close
    
    Return Null
End Sub
 

Attachments

  • meapague.zip
    11.5 KB · Views: 179

LucaMs

Expert
Licensed User
Longtime User
  1. Wait For (sp.RootPane) sp_AnimationCompleted - sp.RootPane is not an event.
  2. xui.MsgboxAsync("Servidor... - it is asynchronous and you don't wait (see attached project)
  3. MainForm.Show - move it before Wait For (liberar)... I don't understand why this is needed!
 

Attachments

  • meapague_lm.zip
    11.5 KB · Views: 188
Last edited:
Upvote 0
Top