Hi,
I want to do some Jobs on start of an App. Since there are user interactions and I have to handle with MsgBoxAsync and Wait For, there are Services to start and so on, it's quite difficult to keep the order of the jobs.
Especially because anything runs in Activity_Create, and some jobs should run in Activity_Resume, but only after the other jobs are done...
So I try to put anything in little classes and created a JobListClass, which handles them.
In Main I have
The Jobs only have to have a Sub called runJob:
The JobListClass isn't very complicated, too:
Well, the whole thing runs until the "Wait For (CallSub(Job, ..." in the JobListClass. The job itself starts and ends, but the Wait For never seems to fire the Complete event.
Why?
I want to do some Jobs on start of an App. Since there are user interactions and I have to handle with MsgBoxAsync and Wait For, there are Services to start and so on, it's quite difficult to keep the order of the jobs.
Especially because anything runs in Activity_Create, and some jobs should run in Activity_Resume, but only after the other jobs are done...
So I try to put anything in little classes and created a JobListClass, which handles them.
In Main I have
Main:
Sub Process_Globals
Private jobList As JobListClass
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
Log("Test startet...")
jobList.Initialize
Dim job As JobClass
job.Initialize
jobList.addJob(job, "First Job")
jobList.runJobs
End Sub
The Jobs only have to have a Sub called runJob:
JobClass:
Public Sub runJob As ResumableSub
Log("runJob: started")
Dim sf As Object = Msgbox2Async("Hello World.", "Info", "OK", "", "", Null, False)
Wait For (sf) MsgBox_Result (ret As Int)
Log("runJob: ready.")
Return 0
End Sub
The JobListClass isn't very complicated, too:
JobListClass:
Sub Class_Globals
Private JobList As List
Private Running As Boolean
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
JobList.Initialize
Running = False
End Sub
' Füge einen Job der Liste zu
Public Sub addJob(Job As Object, text As String)
If SubExists(Job, "runJob") Then
JobList.Add(Job)
Log("JobListClass: " & text & " added.")
Else
Log("JobListClass: " & text & " has no Sub runJob!")
End If
End Sub
' Jobs laufen lassen
Public Sub runJobs
If Running Then
Log("JobList.runJobs: jobs are already running")
Return
End If
Running = True
' Die Jobs sollen im Hintergrund laufen
Sleep(0)
Do While JobList.Size > 0
Dim job As Object = JobList.Get(0)
JobList.RemoveAt(0)
Log("runJobs: starting job...")
Wait For (CallSub(job, "runJob")) Complete (dummy As Object)
Log("runJobs: job ended. Jobs left: " & JobList.Size)
Loop
Running = False
End Sub
Well, the whole thing runs until the "Wait For (CallSub(Job, ..." in the JobListClass. The job itself starts and ends, but the Wait For never seems to fire the Complete event.
Why?