[wxruby-users] New problem: Newlines.

Alex Fenton alex at pressure.to
Thu Jan 8 15:52:29 EST 2009


Tim Mcd wrote:
> Oh and also, is it possible/would it be 'correct' for me to add some 
> stuff into the 'main_loop'? I would like to add something like:
>
> def main_loop
>  Thread.new do ||
>     inp = connection.recv(1000000)
>     display.write_text inp
>   end
> end
>
> would that screw with what is already in the main_loop too much?
>   

It should work OK, but you'll need to add something like

Wx::Timer.every(50) { Thread.pass }

to your main_loop. This will ensure that on Ruby 1.8 your non-GUI ruby 
threads get execution time, otherwise they won't progress.

Have a look at the threaded.rb and chat client examples in the samples 
directory as they demonstrate threads and network programming.

hth
alex



More information about the wxruby-users mailing list