# GUI Responsiveness

**URL:** <https://www.ruby-forum.com/t/gui-responsiveness/178514>\
**Category:** wxRuby\
**Created:** [November 5, 2009, 7:09pm UTC](https://www.ruby-forum.com/t/gui-responsiveness/178514 "2009-11-05T19:09:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![el-gato](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@el-gato](https://www.ruby-forum.com/u/el-gato)\
**Post date:** [November 5, 2009, 7:09pm UTC](https://www.ruby-forum.com/t/gui-responsiveness/178514/1 "2009-11-05T19:09:04Z")

</div>

I’m having a heck of a time trying to keep my app appearing responsive  
while shelling out to long running commands / downloading large files.  
I’ve read everything I can find on the subject, which got me what I have  
now, but nothing I try seems to work. How do I keep the interface  
refreshed so that it’s not just a plain white box after other windows  
are opened over it, etc? Below is a rough idea of what I have. What am  
I missing?

def on\_init  
t = Wx::Timer.new(self, 55)  
evt\_timer(55) { Thread.pass }  
t.start(25)

@frame = MyFrame.new  
@frame.show  
end

class MyFrame  
…  
def on\_download(event)  
…  
Thread.new { download(file) }  
…  
end

# on an event, download the file

def download(file\_obj)  
Wx::WindowDisabler.disable(self) do  
info = Wx::BusyInfo.busy(‘Please wait…’, self) do  
Wx::log\_message(“Getting file #{file\_obj.name}”)  
file\_obj.fetch # uses open-uri to get a large binary  
end  
end  
…  
end  
end

---

<div class="post-metadata">

**Author:** ![el-gato](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@el-gato](https://www.ruby-forum.com/u/el-gato)\
**Post date:** [November 6, 2009, 1:46am UTC](https://www.ruby-forum.com/t/gui-responsiveness/178514/2 "2009-11-06T01:46:30Z")

</div>

Hello El,

On Thu, Nov 5, 2009 at 1:09 PM, El Gato [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> evt\_timer(55) { Thread.pass }  
> Thread.new { download(file) }  
> end  
> …  
> end  
> end

There needs to be a Thread.pass in whatever your fetch method on  
file\_obj  
runs, if your downloading a file, then you need to use Async Sockets,  
and  
utilize IO.select() to detect activity on a socket, if no activity, do a  
Thread.pass, if there is activity, read it, then do a Thread.pass.

It has to work between the Main thread, which handles the Ruby events,  
and  
the wxWidgets thread, which handles the GUI events internally.

hth,

Mario
