Android Question Synchronicity

MrKim

Well-Known Member
Licensed User
Longtime User
Sigh, I really struggle with this whole Asynchronous thing. I have a routine that runs DbRequestmanager. Works Fine but I wanted to run it from more than one place so I moved it to a Module. That didn't work because it requires an object to initialize the callback (Me) so I moved it to a classmodule.
That's fine except the problem is I need to disable a button when the routine is run manually (not in the background). The only way I found to do this is to re-enable the button in the JobDone routine after the final update. BUT you can't directly reference a button in an activity from a class module so I wrote a sub in the activity to re-enable the Button and use call subdelayed to re-enable the button. Then I realized I don't want to be queuing up a bunch of messages to start an activity I am not currently using so I added parameter to the Call to tell the routine whether it NEEDS to run the Callsubdelayed. (I hope this makes sense.)

So what is my question? Is this the cleanest way to do this? I thought about a DoEvents loop after the call that would wait for a flag but that is just ugly. I really don't want to duplicate a whole bunch of code just to make it easier to disable/enable a button. In VBA if you shell out to run a command you have an option to wait for the called routine to finish or continue on. I am just a dumb database programmer so I have no idea how hard this would be to implement but a WAIT option on a call would sure be wonderful addition. The program would wait the call was completed before continuing.
 

thedesolatesoul

Expert
Licensed User
Longtime User
If you dont want the activity to start can you not use CallSub instead of CallSubDelayed?
[Personally I like to use CallSubDelayed to de-couple events, so I use a double indirection sometimes, a CallSubDelayed to a sub in the current class that callsubs the activity/parent]

Event based programming isnt the prettiest or most readable. But it is a proper way to program asynchronous tasks.
You need to create and hook up event subs from your active blocks in the most logical way. Just take a step back to imagine the flow of the program and then design it.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Call sub won't work because the Activity is paused because I am running the other code.
Yeah, 25 years of good 'ol linear programming makes it difficult. I can always figure out a way to make it work, it just seems so UNCLEAN, and since I am knew at it I keep looking at what I am doing and thinking there MUST be a better way! Understanding what can talk to what and when is a big part of it. I'm not used to creating so many Global variables to make things wok either. Hard to keep track of things when you have as bad a memory as I do. I'm used to seeing just about every dim I need at the top of my subroutine.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Is there some document that lists all these rules?
It would really be helpful.
 
Upvote 0
Top