JobProgressTotal:Long ( job )
Parameters
| job - a Job handle returned by StartJob |
Description
|
Returns the raw total-work count from the worker's latest progress snapshot. This is the total argument of the worker's latest SetJobProgress call, as a Long - the denominator that goes with JobProgressDone: "3,410 of 12,000 tiles". It returns 0 until the worker publishes its first snapshot, so guard a division with an If total > 0 check. The total is whatever the worker last said it was, and a worker moving into a new phase may publish a different total mid-job. Display it, but leave decisions to JobFinished, PollJob, and JobState - and use the pre-normalized JobProgress when all you want is a bar. For the full story, see the Using Background Jobs guide. Requires Extended mode. See also: JobProgressDone, JobProgress, JobProgressText, SetJobProgress. |
Example
; JobProgressTotal Example ; ------------------------ ; Requires Extended mode. Graphics 640,480,0,2 SetBuffer BackBuffer() ; The worker carves a dungeon level on a background thread Worker Function CarveDungeon(inputBank) rooms=PeekInt(inputBank,0) For room=1 To rooms ; Busy digging loop standing in for real level generation For dig=1 To 700000 noise#=Sin(dig)*Sqr(dig) Next ; Each snapshot's raw total value is what JobProgressTotal reports SetJobProgress room,rooms,"Carving room "+room Next Return CreateBank() End Function ; Press Space before the job finishes to see total change with a bigger level inputBank=CreateBank(4) PokeInt inputBank,0,20 job=StartJob(CarveDungeon,inputBank,1L) FreeBank inputBank While Not KeyDown(1) Cls ; Space queues a larger dungeon so the published total differs If KeyHit(57) And JobFinished(job) FreeJob job inputBank=CreateBank(4) PokeInt inputBank,0,40 job=StartJob(CarveDungeon,inputBank,2L) FreeBank inputBank EndIf ; JobProgressTotal returns the latest raw total-work value total:Long=JobProgressTotal(job) done:Long=JobProgressDone(job) ; Draw the loading bar from the normalized progress progress=JobProgress(job) Color 60,60,80 Rect 70,220,500,24,True Color 90,200,120 Rect 70,220,progress*500/1000,24,True Color 255,255,255 Rect 70,220,500,24,False Text 0,0,"Space: queue a 40 room dungeon when done Esc: exit" Text 70,190,"Generating dungeon on a worker thread..." Text 70,254,"JobProgressTotal(job) = "+total+" rooms planned, "+done+" carved" If JobFinished(job) Then Text 70,274,"Dungeon complete!" Flip Wend FreeJob job End
Index