threads
Ned Konz
ned at bike-nomad.com
Sun Mar 23 22:56:56 UTC 2003
On Sunday 23 March 2003 02:44 pm, Janet Abdul-Karim wrote:
> I am creating a program in squeak where I can update stock info
> from the web. I need a way to use a thread so that i can use a
> delay that last 24 hours and not lock up the gui..
No problem.
delay := Delay forSeconds: 60 * 60 * 24.
[
delay wait.
"now do whatever"
] forkAt: Processor userBackgroundPriority.
Note, though, that you can't do UI stuff from a background thread
(Squeak calls them Processes) safely.
There are safe ways to do it, though:
1. You can set up a SharedQueue between your background Process and
your UI Morph. The Morph can then check the queue in its #step method
(check to see if anything is on the queue first, so you don't hang
the UI).
2. You can post a message or block to be evaluated from the UI
process:
WorldState addDeferredUIMessage: [ "do something here" ].
Actually, instead of a block you could use any object that responds to
#value.
For instance:
WorldState addDeferredUIMessage: (MessageSend receiver: myMorph
selector: #color: arguments: { Color red }).
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|