S Scantech Well-Known Member Licensed User Longtime User Apr 5, 2019 #1 I am interested if there is anything that deals with Callsub and wait for the sub is ended. Is there any examples of this? I need to call a sub in Main from Service. If Main is paused it will still call it and trigger the sub and wait for the sub to end. Code: CallSub(Main, "Testing") 'Need to wait here until the Testing Sub is Ended
I am interested if there is anything that deals with Callsub and wait for the sub is ended. Is there any examples of this? I need to call a sub in Main from Service. If Main is paused it will still call it and trigger the sub and wait for the sub to end. Code: CallSub(Main, "Testing") 'Need to wait here until the Testing Sub is Ended
DonManfred Expert Licensed User Longtime User Apr 5, 2019 #2 Probably it is better to use CallSubDelayed as it will start the activity if not running. For the rest: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/ https://www.b4x.com/android/forum/threads/b4x-resumable-subs-that-return-values-resumablesub.82670/ Upvote 0
Probably it is better to use CallSubDelayed as it will start the activity if not running. For the rest: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/ https://www.b4x.com/android/forum/threads/b4x-resumable-subs-that-return-values-resumablesub.82670/
Erel B4X founder Staff member Licensed User Longtime User Apr 5, 2019 #3 I assume that Main.Testing is a resumable sub. Otherwise you don't need to do anything special. Code: Sub Testing As ResumableSub ... 'different module Dim rs As ResumableSub = CallSub(Main, "Testing") if rs.IsInitialized Then Wait For (rs) Complete (Result As Object) 'after Else Log("Activity was paused") End If Upvote 0
I assume that Main.Testing is a resumable sub. Otherwise you don't need to do anything special. Code: Sub Testing As ResumableSub ... 'different module Dim rs As ResumableSub = CallSub(Main, "Testing") if rs.IsInitialized Then Wait For (rs) Complete (Result As Object) 'after Else Log("Activity was paused") End If
S Scantech Well-Known Member Licensed User Longtime User Apr 5, 2019 #4 Erel said: I assume that Main.Testing is a resumable sub. Otherwise you don't need to do anything special. Code: Sub Testing As ResumableSub ... 'different module Dim rs As ResumableSub = CallSub(Main, "Testing") if rs.IsInitialized Then Wait For (rs) Complete (Result As Object) 'after Else Log("Activity was paused") End If Click to expand... I thought Anything after CallSub will have to wait for the sub to be completed? But when you use CallSubDelayed it will go to next code with out waiting? Can this be used with CallSubDelayed. I want to unpause the Main and make the call and wait for completion. Last edited: Apr 5, 2019 Upvote 0
Erel said: I assume that Main.Testing is a resumable sub. Otherwise you don't need to do anything special. Code: Sub Testing As ResumableSub ... 'different module Dim rs As ResumableSub = CallSub(Main, "Testing") if rs.IsInitialized Then Wait For (rs) Complete (Result As Object) 'after Else Log("Activity was paused") End If Click to expand... I thought Anything after CallSub will have to wait for the sub to be completed? But when you use CallSubDelayed it will go to next code with out waiting? Can this be used with CallSubDelayed. I want to unpause the Main and make the call and wait for completion.
S Scantech Well-Known Member Licensed User Longtime User Apr 5, 2019 #5 Code: Sub Service_Create CallSub(Main, "Testing") Log("After CallSub in Service") End Sub Code: Sub Testing For x = 0 To 20000 Log("TESTING IN MAIN " & x) Next End Sub This works but i need to use Callsubdelayed to unpause the activity Upvote 0
Code: Sub Service_Create CallSub(Main, "Testing") Log("After CallSub in Service") End Sub Code: Sub Testing For x = 0 To 20000 Log("TESTING IN MAIN " & x) Next End Sub This works but i need to use Callsubdelayed to unpause the activity
S Scantech Well-Known Member Licensed User Longtime User Apr 5, 2019 #6 DonManfred said: Probably it is better to use CallSubDelayed as it will start the activity if not running. For the rest: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/ https://www.b4x.com/android/forum/threads/b4x-resumable-subs-that-return-values-resumablesub.82670/ Click to expand... Yes, i need to wait for the sub being called and be completed before it goes to next line after CallsubDelayed. Upvote 0
DonManfred said: Probably it is better to use CallSubDelayed as it will start the activity if not running. For the rest: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/ https://www.b4x.com/android/forum/threads/b4x-resumable-subs-that-return-values-resumablesub.82670/ Click to expand... Yes, i need to wait for the sub being called and be completed before it goes to next line after CallsubDelayed.
S Scantech Well-Known Member Licensed User Longtime User Apr 5, 2019 #7 This is the difference with Erels Example. 'Erels Example above Code: Sub Service_Create 'different module Dim rs As ResumableSub = CallSub(Main, "Testing") If rs.IsInitialized Then Wait For (rs) Complete (Result As Object) Log("AFTER WAITING") Else Log("Activity was paused") End If End Sub Code: Sub Testing As ResumableSub Log("TESTING") End Sub 'Result *** Service (starter) Create *** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** *** Service (doing) Create *** TESTING ** Service (doing) Start ** AFTER WAITING ** Activity (main) Pause, UserClosed = true ** ** Service (starter) Destroy (ignored)** ** Service (doing) Destroy ** Click to expand... 'This Example Code: Sub Service_Create 'different module CallSub(Main, "Testing") Log("AFTER WAITING") End Sub Code: Sub Testing As ResumableSub Log("TESTING") End Sub 'Result *** Service (starter) Create *** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** *** Service (doing) Create *** TESTING AFTER WAITING ** Service (doing) Start ** ** Activity (main) Pause, UserClosed = true ** ** Service (starter) Destroy (ignored)** ** Service (doing) Destroy ** Click to expand... Notice the difference with **Service(doing)Start** Upvote 0
This is the difference with Erels Example. 'Erels Example above Code: Sub Service_Create 'different module Dim rs As ResumableSub = CallSub(Main, "Testing") If rs.IsInitialized Then Wait For (rs) Complete (Result As Object) Log("AFTER WAITING") Else Log("Activity was paused") End If End Sub Code: Sub Testing As ResumableSub Log("TESTING") End Sub 'Result *** Service (starter) Create *** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** *** Service (doing) Create *** TESTING ** Service (doing) Start ** AFTER WAITING ** Activity (main) Pause, UserClosed = true ** ** Service (starter) Destroy (ignored)** ** Service (doing) Destroy ** Click to expand... 'This Example Code: Sub Service_Create 'different module CallSub(Main, "Testing") Log("AFTER WAITING") End Sub Code: Sub Testing As ResumableSub Log("TESTING") End Sub 'Result *** Service (starter) Create *** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** *** Service (doing) Create *** TESTING AFTER WAITING ** Service (doing) Start ** ** Activity (main) Pause, UserClosed = true ** ** Service (starter) Destroy (ignored)** ** Service (doing) Destroy ** Click to expand... Notice the difference with **Service(doing)Start**
Erel B4X founder Staff member Licensed User Longtime User Apr 7, 2019 #8 This thread is very unclear. You should start a new thread and better explain what you are trying to do. Upvote 0
This thread is very unclear. You should start a new thread and better explain what you are trying to do.