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

Karl Varga kjvarga at gmail.com
Mon May 18 05:55:27 PDT 2009


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


More information about the MacRuby-devel mailing list