1.9 Threads in a GUI not behaving as expected (Windows)

Discussion in 'Ruby' started by Michael, Mar 14, 2011.

  1. Michael

    Michael Guest

    I have an app with an FXRuby UI that does some fairly heavy data
    processing. I've implemented an extension to put the processing into
    C, so all is right the world there.

    The issue is that I'm attempting to kick off the processing in a
    separate thread to keep the UI responsive to the user, and it isn't
    working. I was under the impression that 1.9 threads were no longer
    "green threads" and shouldn't behave in this manner since they're
    *actual* threads now.

    I would be perfectly happy using fork for this, except fork isn't
    available on windows and the win32-process gem doesn't look to be a
    solution for me (I've already investigated it).

    My dev box is a Win7 box, but the clients machine will be a WinXP
    machine.

    I've included an excerpt where I'm creating the thread in the hopes
    that someone can help identify why the UI thread appears to be getting
    starved for time. There's not much there, so if you need something
    more, please let me know.

    Thread.new {
    # call extension function
    }
    Michael, Mar 14, 2011
    #1
    1. Advertising

  2. Michael

    Dave Lilley Guest

    Sorry I cannot help you with threads but how about the use of a timer?

    here is an extract of code I've used to have a timer count down and have
    an event fire ever X milliseconds and so allows user GUI interaction to
    continue without delays.

    NOTE the @timer object allows for the "destruction" or cancellation of
    the timer and the creation of it again depending on user events /
    actions within the program.

    when 3 #Esc Pressed OR clicked on
    begin
    if @timer == true
    @mydb.copy_record('patrols',@PSlist3.getItemText(@PSlist3.currentItem).to_s,'status','Countdown
    STOPPED - CALL ASAP for COMFIRMATION!!')
    $fxapp.removeTimeout(@timeout)
    @timer = false
    else
    Showmsg 'Msg would be sent to another user and resent until
    keys are repressed again!', 'ALERT ALERT ALERT....'
    @mydb.copy_record('some
    text',@PSlist3.getItemText(@PSlist3.currentItem).to_s,'status','OOPS
    PANIC ! - Countdown started!!')
    @timer = true
    @timeout = $fxapp.addTimeout(2000*12, :repeat => true) do
    |sender, sel, data|
    @PSlist2.appendItem("#{Time.now}")
    end
    end

    The magic is this code below...

    @timeout = $fxapp.addTimeout(2000*12, :repeat => true) {|sender, sel,
    data| @PSlist2.appendItem("#{Time.now}") }

    so try this...

    def init
    @timeout = $fxapp.addTimeout(2000*12, :repeat => true) {|sender, sel,
    data| @label1.text = Time.now.strftime("%d/%m/%Y %H:%M:%S")}
    end


    HTH

    Dave.

    --
    Posted via http://www.ruby-forum.com/.
    Dave Lilley, Mar 15, 2011
    #2
    1. Advertising

  3. Michael

    Roger Pack Guest

    Roger Pack, Mar 23, 2011
    #3
  4. Michael

    Michael Guest

    On Mar 23, 9:37 am, Roger Pack <> wrote:
    > Your c block needs to be within rb_thread_blocking_region to not block
    > the (UI responding) ruby threads, I'm thinking.
    >
    > ref:http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Threa....
    >
    > --
    > Posted viahttp://www.ruby-forum.com/.


    Thanks Roger, that's what I ended up doing, and it's working
    beautifully :)
    Michael, Apr 8, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Kafieh
    Replies:
    7
    Views:
    2,485
    Roedy Green
    May 19, 2004
  2. William Krick
    Replies:
    4
    Views:
    77,848
    rt19983
    Dec 18, 2008
  3. Skip Montanaro

    sys._getframe() not behaving as expected

    Skip Montanaro, Dec 1, 2003, in forum: Python
    Replies:
    0
    Views:
    352
    Skip Montanaro
    Dec 1, 2003
  4. Replies:
    1
    Views:
    343
    David
    Apr 16, 2007
  5. Steve Richter
    Replies:
    2
    Views:
    599
    Steve Richter
    May 29, 2007
Loading...

Share This Page