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

M

Michael

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
}
 
D

Dave Lilley

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top