From: Robert Klemme Date: 2011-10-12T05:11:07+09:00 Subject: Re: scheduler and thread On Tue, Oct 11, 2011 at 6:04 PM, lover ruby wrote: > Robert Klemme wrote in post #1026082: >> On Tue, Oct 11, 2011 at 8:08 AM, lover ruby >> wrote: >>>>> 1318284733 >>>>    loop do >>>>    @timer.kill >>>> >>>> Sam >>> UI.start_timer, every code is executable. So the UI.start_timer acts >>> like a background process. >> >> Then you must not #join in the method that start the thread as Sam >> explained. >> >> Example: >> https://gist.github.com/1278320 >> >> Kind regards >> >> robert > > Thanks > I tried you code, but still need sleep 20. what I really want > > require 'timer' > Timer.repeat_every(5) do >  puts Time.now.to_i > end > > puts "Doing other stuff..." > #sleep 20 > > The output will be > "Doing other stuff..." > 1318348633 > 1318348638 > 1318348643 > 1318348633 > 1318348638 > 1318348643 > ..........Forever, always print out number every 5 seconds Then you better exchange foreground and background task: Thread.new do puts "Doing other stuff..." end loop do puts Time.now.to_i sleep 5 end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/