B4J Question How to question: write to form while sub is running

TorontoJim

Active Member
Licensed User
Longtime User
I'm working on an app where the user clicks a button to perform a function. I want to write to a new form/textarea while that sub is running. However, the program display freezes up while that subroutine is running. That is, the form starts to launch, I see the outline of it, but it doesn't fully render until after the subroutine finishes (processing on a 150Mb file).

So this may be obvious to all but this humble noob, how to I get that process to run without freezing up the form? OR, how to I get the form to display without being frozen up?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You have two options:
1. Split the large task into smaller tasks and use CallSubDelayed to run the first task and when it completes use CallSubDelayed again to start the next one until you finish processing the large file. This will allow the main thread to process the message queue and update the UI.

2. Use B4A Threading library to run the task on a background thread.
 
Upvote 0

TorontoJim

Active Member
Licensed User
Longtime User
Thank you for the response. I was looking at the CallSubDelayed. Would I use it something like this (understanding I just want to get the order right):

B4X:
Sub NiftyStuff
   OtherFormModule.Show
   CallSubDelayed(OtherFormModule, ProcessThis)
   CallSubDelayed(OtherFormModule, UpdateProgressBarOnOtherForm)
  CallSubDelayed(OtherFormModule, ShowSomeResults)
  CallSubDelayed(OtherFormModule, UpdateProgressBarOnOtherForm)
  CallSubDelayed(OtherFormModule, ShowSomeMoreResults)
  ...etc...
End Sub

I'm just trying to sus out what I read here:
https://www.b4x.com/android/forum/t...etween-activities-and-services.18691/#content
 
Upvote 0
Top