[MacRuby-devel] creating threads in a macruby gui app

Dr Rebs Rebo rebotfc at googlemail.com
Mon May 18 06:10:16 PDT 2009


 From what I can make out threads such as  NSThreads or NSOperations  
are not supported by macruby yet.

On 18 May 2009, at 13:55, Karl Varga wrote:

> I am wondering whether MacRuby 0.5 supports Cocoa threads?  I have an
> application which runs in the background and which displays
> information in the system status bar (in a menu).  It periodically
> logs into a website, retrives information and sets that information in
> the menu.
>
> The problem is that if I run this loop in the awakeFromNib method it
> occupies the current thread and the menu is unresponsive until that
> method returns.  I've tried creating Cocoa threads but my application
> goes haywire (in XCode it enters the debugger and is otherwise
> unresponsive).
>
> What gives?  Any idea how I can achieve what I want to do here?  If
> the answer is POSIX threads or something, can I call back to (mac)ruby
> because that is where all my logic is?
>
> Below is the code I've tried:
>
> def awakeFromNib
>    print NSThread.isMultiThreaded() # prints true
>     
> self 
> .menu.performSelectorInBackground_withObject_(:loginAndWaitThread,  
> nil)
>     
> NSThread 
> .detachNewThreadSelector_toTarget_withObject_(:loginAndWaitThread,
> self.menu, nil)
> end
>
> -- 
> Karl Varga
> kjvarga at gmail.com
> Cell: +61 (0)4 2075 1356
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list