On Sun, Nov 14, 2010 at 12:46:00AM +0100, seb wrote:
> Hello,
> 
> I want to start a methods at the creation of an object, and every second give 
> me status of somme of his variable. When i create the instance I can see in 
> the Transcript the output expected. But the squeak interface freeze (and 
> processor goes to 100%). How can I make this method execute in background?
> 
> Here is my buggy method:
> 
> MyClass>>beeper
>        [ self beeperOn ] whileTrue: [
>               Transcript show: self myStatus; cr.
>               ( Delay forSeconds: 1) wait.
>               ]

S?bastien,

This is a good question, and the answer is not at all obvious. Squeak uses
threads of execution called Processes. The things that interact with the
user interface are expected to run within the single process that handles
the user interface. User interface objects require this (it is an intentional
design decision, not a bug), so if you start your own background process
that needs to interact with the UI, the background process needs to schedule
its UI related activities into the main UI process. This is done with the
#addDeferredUIMessage: method. You can look for senders of 
#addDeferredUIMessage:
for examples, but I think that the following will do what you want:

MyClass>>beeper
   [ self beeperOn ] whileTrue: [
       Project current addDeferredUIMessage: [Transcript show: self myStatus; 
cr].
       ( Delay forSeconds: 1) wait.
       ]

Dave

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to