B4J Question [SOLVED] Background Workers : passing parameters ?

lemonisdead

Well-Known Member
Licensed User
Hello,
Something I don't understand with Background Workers is their use (apart from doing fixed tasks at interval as the example said).

For instance : I have tried to pass a variable in a separate sub, as an initialization parameter but they seem not to be got.
Only when the Background Worker requests the variable from the Main thread, it exists. When the variable is sent while initialization, it produces an error ; OK.

So, please can we use any amount of background workers to do something different from each one ?
Thanks
 

Attachments

  • bgWorkers.zip
    2.7 KB · Views: 147
Last edited:

mindful

Active Member
Licensed User
You can use as many background workers as you like. You can declare the in you Main module and set them in the bg worker initialization method.

Code from bg worker:
B4X:
Sub Initialize
Main.YourBg = Me
End Sub

Code from other module or class:
B4X:
Main.YourBg.YourMethod(YourVar)

There was another post where @Erel explains the same thing.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Many thanks. I will try your suggestion. I have missed Erel's post about.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Definitively thanks, it cleared the things (example attached). The only thing I am not happy with is the not elegant way I attribute the background worker to a variable.
I will have to work on that :)
 

Attachments

  • bgWorkers1.zip
    1.5 KB · Views: 171
Upvote 0
Top