From: Eleanor McHugh Date: 2009-09-06T00:17:33+09:00 Subject: Re: Problems with cross-thread violation On 3 Sep 2009, at 03:08, Gin Mendi wrote: > Thanks again for taking the time to read this! > > require 'feed_library' > > # my callback for the live feed > FEED_CALLBACK = DL.callback('0PL') { |result_list, count| } > if result_list > record = FeedRecord.new(result_list) > puts record.code > end > } > > # handle used to request for a feed > handle = FeedLibrary::log_on("user", "password") > > session = get_live_feed(handle, FEED_CALLBACK) > > # my attempt to keep this running and waiting on the callback: > while true > > end No need to be uncivilised ;) Idiomatic Ruby for an endless loop is better expressed as: loop do end although that shouldn't make any difference to your program. > Here's one I tried. Been playing around with different approaches. > With > this method I noticed I always get the cross-thread violation when I > use > the FeedRecord structure. If I don't use the structure and do > something > else like using the struct! method I'm able to get away with the > callback being performed a couple of times then it eventually leads > to a > cross-thread violation. Does get_live_feed use a separate thread internally? If so the cross- thread violation could well be related to garbage collection of the callback in which case you may need a separate callback instance for each feed handle. Also I note that you're using a constant to hold the callback, have you tried using a variable instead? Try turning off garbage collection altogether and see whether that affects the errors you receive. I've had some very amusing results doing that with DL callbacks :) Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason