B4A Class [B4X] CallSubPlus - CallSub with explicit delay

Discussion in 'Additional libraries, classes and official updates' started by Erel, Nov 30, 2015.

  1. pesquera

    pesquera Active Member Licensed User

    What could happen if not? I must to use CallSubDelayedPlus and wanted to know more about that

    I noticed on ClientKVS Class that you does not include an underscore on the Sub HandleQueue, and seems to be fine compiling with obfuscation
    Code:
    csu.CallSubDelayedPlus(Me, "HandleQueue"30000)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Check the last line in ClientKVS.Initialize:
    Code:
    If False Then CallSub(Me, "HandleQueue"'to avoid obfuscation issues
    This line causes the compiler to avoid obfuscating HandleQueue name.
     
    jmon and lemonisdead like this.
  3. swissmade

    swissmade Active Member Licensed User

    Hi
    I know this is B4A but is this also working for B4J??
     
  4. DonManfred

    DonManfred Expert Licensed User

    I guess yes as it is a CLASS....
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Yes (see the notes in the first post). It also works with B4i
     
  6. Dave O

    Dave O Active Member Licensed User

    This is very handy when dealing with animations.

    For example, when the user opens the nav drawer and taps an item, the nav drawer typically takes ~100ms to close. When I tried updating the UI on the activity, it caused the drawer animation to stutter (because they were happening at the same time).

    Using CallSubDelayedPlus, however, I give it a 150ms delay and everything is smoothy goodness. :)

    Thanks Erel!
     
    lemonisdead, inakigarm and Erel like this.
  7. Stern0m1

    Stern0m1 Member Licensed User

    How could I add the option to cancel the scheduled task?

    Thanks
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You can add a global flag and check it in the target sub.
     
  9. Stern0m1

    Stern0m1 Member Licensed User

    Thats what I have been doing. I think a more efficient way would just be a command to cancel. There should be a way to timer.enabled = false in the class. I just dont know anything about classes.

    Thanks
     
  10. ilan

    ilan Expert Licensed User

    hi,

    i have a question please.

    i see now that in the CallSubUtils Class in tmr_Tick
    when rdd.Delayed is false then the sub will be called with CallSub and not CallSubDelayed. that make sense because this is what we want. (use CallSub and not CallSubDelayed, only in speciffic cases like calling a sub inside the same module)

    but my question is, if you call a sub with CallSub and the Module is Paused then you may get a crash right?

    should there not be an if statement before trying to call that sub??

    this is the original code:

    Code:
    Private Sub tmr_Tick
        
    Dim t As Timer = Sender
        t.Enabled = 
    False
        
    Dim rdd As RunDelayedData = RunDelayed.Get(t)
        RunDelayed.Remove(t)
        
    If rdd.Delayed Then
            
    If rdd.Arg = Null Then
                CallSubDelayed(rdd.Module, rdd.SubName)
            
    Else
                CallSubDelayed2(rdd.Module, rdd.SubName, rdd.Arg)
            
    End If
        
    Else
            
    If rdd.Arg = Null Then
                
    CallSub(rdd.Module, rdd.SubName)
            
    Else
                
    CallSub2(rdd.Module, rdd.SubName, rdd.Arg)
            
    End If
        
    End If
    End Sub
    this is how i think it should look like (but i may be wrong)

    Code:
    Private Sub tmr_Tick
        
    Dim t As Timer = Sender
        t.Enabled = 
    False
        
    Dim rdd As RunDelayedData = RunDelayed.Get(t)
        RunDelayed.Remove(t)
        
    If rdd.Delayed Then
            
    If rdd.Arg = Null Then
                CallSubDelayed(rdd.Module, rdd.SubName)
            
    Else
                CallSubDelayed2(rdd.Module, rdd.SubName, rdd.Arg)
            
    End If
        
    Else
            
    If IsPaused(rdd.Module) Then Return 'CHECK FIRST IF MODULE IS NOT PAUSED
            If rdd.Arg = Null Then
                
    CallSub(rdd.Module, rdd.SubName)
            
    Else
                
    CallSub2(rdd.Module, rdd.SubName, rdd.Arg)
            
    End If
        
    End If
    End Sub
     
  11. LucaMs

    LucaMs Expert Licensed User

    No.
     
  12. ilan

    ilan Expert Licensed User

    I did. I understand that only an emty string should be returned but with the csu class the timer crashed once.
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    CallSub will never crash because of a paused activity.
     
  14. ilan

    ilan Expert Licensed User

    i could reproduce it in this simple example.

    the crash is related to the timers in CallSubUtils

    when you intialize callsubuitls in the starter service and then call it from 1 activity but before the timer tick was called you switch to another activity you may get this error:

    what i did to solve it i check if the activity is paused, if true then it wont be called with callsub.
    i also stop all timers and delete them when i exit my app. this function is important.

    Code:
    Public Sub StopAll
            
    If RunDelayed.IsInitialized Then
                
    For Each tmr As Timer In RunDelayed.Keys
                    tmr.Enabled = 
    False
                
    Next
                RunDelayed.Clear
            
    End If       
    End Sub
    let say i want to show an ad in 2 seconds so i call csu.... now if the user exit the app then it is not relevant anymore to show that ad so i stop all timers and clear the map otherwise when he will return the timer event will be raised and i dont want that. so the StopAll function is important is some cases.
     

    Attached Files:

  15. Erel

    Erel Administrator Staff Member Licensed User

    I don't see any crash here (tested in debug mode). I pressed on Show msg and then switched activity.

    The error message you posted looks like a debugger error. Do you see an error in release mode?
     
  16. ilan

    ilan Expert Licensed User

    in release mode i cant reproduce it but yesterday i am sure i got the same error in release mode.
    when i returned to the app i was thrown out and i saw the same error (something with the timer in csu class)

    i need to mention that i exit the app with home button. i am not sure if it is related to that.
    will make more tests and let you know if i found something.

    thanx, ilan
     
  17. ilan

    ilan Expert Licensed User

    ok i got a crash on release mode on my app, this is the log:

    EDIT: it could be because the csu was intialized in activity main, i moved it to starter service let see if i get that crash again.

    btw is there a reason why the CallSubUtils "Library" (not class) does not compile on debug mode?
     
    Last edited: Mar 24, 2017
  18. Erel

    Erel Administrator Staff Member Licensed User

    It works fine here in debug mode. Please start a new thread in the questions forum and explain what is not working.
     
  19. Vanessa Maldonado

    Vanessa Maldonado New Member Licensed User

    I would like to use this class, where could I download the library? :(
     
  20. DonManfred

    DonManfred Expert Licensed User

    It is included in the IDE Installation in B4A 6.8 or so.... Just look out for the library "CallSubUtils" in the Library-Tab

    PD: Welcome in the B4X Community!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice