...
In my recent background task progress bars example I went for a marginally simpler approach: the Start()ed task procedure looks like any other process but includes a bit of code before, after, and inside the loop to handle the control aspect. I still need to derive a virtual method, but in this case it’s the method that does the actual Start()ing.
Adding thread control
My first challenge was to modify my original threading class to handle starting and stopping a single instance of a Start()ed procedure.
Here’s what the demo procedure looks like:
Code Block |
---|
MEMBER('ThreadDemo')
MAP
END
ThreadDemo_Main procedure
Window WINDOW('Background thread demo'),AT(,,223,101),GRAY,FONT('Microsoft Sans ' & |
'Serif',8),TIMER(1)
BUTTON('Stop Task'),AT(114,26,70),USE(?StopTask)
BUTTON('Start Task'),AT(28,26,70,14),USE(?StartTask)
STRING('Background process is not running'),AT(28,51),USE(?status)
END
Task class(DCL_System_Threading_Thread)
StartWorkerProcedure procedure,derived
end
CODE
open(window)
accept
case event()
of EVENT:CloseWindow
if not Task.Stopped()
message('Cannot exit while the background Task is running!')
cycle
end
of EVENT:Timer
?status{prop:text} = choose(Task.Stopped(),'Background process is not running','Background process is running')
end
case accepted()
of ?StopTask
Task.Stop()
of ?StartTask
Task.Start()
end
end
close(window)
Task.StartWorkerProcedure procedure!,derived
code
start(ThreadDemo_BackgroundProcess,25000,address(self))
|
...