Android Question Wait for timer event

rossati

Active Member
Licensed User
Longtime User
I would like to execute some code and wait for it to complete, but I can't use Wait For sub because my application is not monolithic, so I'm trying the Timer, that is when the application ends, I start a timer for some time hoping that this may be intercepted.
Unfortunately this does not work: is it a conceptual error or simply a syntax error?
B4X:
Sub fgw(activ As Activity,params As String,handleSub As String)
    resumable = True
    fg_timer.Initialize("fg_timer",100)
    fg(activ,params,"",handleSub)
    Wait for fg_timer_Tick   
    fg_timer.Enabled = False
End Sub
...
    If resumable Then
         fg_timer.Enabled = True
         Return
    End If
Thanks
 

rossati

Active Member
Licensed User
Longtime User
Thank agraham, not monolithic means that in my application I call a sub that calls other subs and it is this last that must be awaited, but it seems that Wait For can't make this.
En passant I haven't find a site whit the syntax of Wait For.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
its similar testing a flag in a timer event.
enable timer
tick event
if flag then do something: end timer


for longer sub routines you still need a sleep call that the event loop continues.
 
Upvote 0

rossati

Active Member
Licensed User
Longtime User
Yes I have
My application is a Form Generator (that you can download from my site www.condorinformatique.com).
I call the Form generator passing the name of the sub for manage the data inserted in the form:
B4X:
      txtParams.Text = "Title,Title,Views creation;" _
                       & "Ground,FF0000FF FF404040;" _
                       & "T,Field,Label field,20,,Insert some text;S,Seek bar,,5,36.5,20 93;" _
                       & "CMB,cmb,Combo box,20,,Alpha|Beta|Delta|Gamma;" _
                       & "CKB,Check,,15;R,Rdb2,Status2,,Single,M:Married|S:Single|W:Widow;After,Check,cmb"
fg.fg(Activity,txtParams.Text,Me,"handleAnswerTest","handleEvents")
' here i would process the form's data
...
I would to avoid the use of this sub (handleAnswerTest in the code above)and process the data in the same sub that requested the creation of the form, but
unfortunately fg.fg makes a callsubdelayed to a sub that creates the form and exits. In other words if I wait fg.fg the wait finish before the form creation.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
and without callsubdelayed,Resumable,sleep it takes so long time?

cascading resumable subs
B4X:
Sub Test
    
    Log("Test Start")
    Wait For (Depth1) Complete (Result As Boolean)
    Log("Result=" & Result)
    Log("Test End")
    
End Sub

Sub Depth1 As ResumableSub
    
    Wait For (Depth2) Complete (Result As Boolean)
    Return Result
    
End Sub


Sub Depth2 As ResumableSub
    
    Wait For (Depth3) Complete (Result As Boolean)
    Return Result
        
End Sub

Sub Depth3 As ResumableSub
    
    Sleep(0)
    
    Log("Depth3 Ready")
    
    Return True
    
End Sub
 
Upvote 0

rossati

Active Member
Licensed User
Longtime User
I want to add a function to generate the form, wait for the conclusion and continue in the same sub that asked for the creation of the form.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
I want to add a function to generate the form, wait for the conclusion and continue in the same sub that asked for the creation of the form.
that was my example showing.

u need this wait for , resumable subs only if your sub would block the main thread and the app would not response for the user.
just creating a form at runtime should not take a long time.
maybe u misapply CallSubDelayed?
 
Last edited:
Upvote 0

rossati

Active Member
Licensed User
Longtime User
Thanks MarcusR your suggestion, I think, can works; but I wouldn't disseminate the form generator of Wait For even because the form generator is rather complex.
The timer seemed to me the simplest solution, provided that Wait For waits even when the timer is disabled.
 
Upvote 0
Top