From: Quintus Date: 2011-10-05T05:59:41+09:00 Subject: Re: WxRuby and blocking issues with a long running function. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 04.10.2011 21:30, schrieb Mark Barton: > Hi All, First time post and please forgive if this is not the right > forum for my question. I have googled a bit, but I haven't come > across anything specific. Your question is wxRuby-specific, so you should post to the wxRuby forum/mailing list; either subscribe at http://wxruby.rubyforge.org/wiki/wiki.pl?MailingLists for the wxruby-users ML or use ruby-forum.com at http://www.ruby-forum.com/forum/wxruby . > I have been programming with Ruby for a while now and just started > getting into using WxRuby for a GUI based application running on > Windows. I'm having an issue with a function call from WxRuby that > takes considerable amount to time to complete as it does spend much > of its time sending and receiving serial data as well as a few > sleeps sprinkled about. I need to be able to update a progress bar > on the GUI screen, but WXRuby is blocked during the call. I have > the long running call in a separate thread and that seems to be > working, but the performance is pretty abysmal, even with a timer > set to allow the thread to run at 10 msec. When it comes to threading, wxRuby has considerable drawbacks. So far I've only been able to do concurrent programming successfully by using separate processes, which I fear on Windows is not an option (missing #fork). Another way is to use wxRuby's progress dialog ( http://wxruby.rubyforge.org/doc/progressdialog.html ) which can be updated easily while doing another operation as it is specifically designed for such cases (but doesn't use threading); it even provides an "abort" button that can easily be intercepted. > Is there a callback to the Wx thread that I can make from the > long running function that will allow the gui to update? I just > need to be able to update a progress gauge as all the other control > are disabled during the call. You _can_ use the Window#refresh and Window#update methods, but this doesn't mean you _should_ use them. You're doing the event loop's work then and the few times I've used it I wasn't really able to get the GUI resonsitive. Vale, Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJOi3OLAAoJELh1XLHFkqhaRx4H/2wvRNLHddOQBvhT9bKPVpVG lkGj2dJ2vjMDsWel+97JzTOjIDv7hZGOut04QUesClpxxEMWd9UrGKtIxJefCZyf 7c7tgmQAKtWuyU1XJsn5vCgueXdxg99i3nwBSNiWqqsHem5r7NSSTVHLhE5ktzuW 2lDH6WGY2VfHLetk3BqUHw8G7abtcs+3NfklgAdJXHVmpQkoHIOm2sXCqMjdogTo o8LXbmAKcXgy9UgCXFJjvMgoZ8u2GOAKV5Q4s1gtm0X3bzAkpiYh3ud9n0g8CXYU 1XmJ9DBkzSPCzy6XyMb3be2+dy3kJsZjD0o/xMSHgfJMX+giIdOQ7e2PP5m632U= =tIR+ -----END PGP SIGNATURE-----