Win32OLE_EVENT and threading

F

Fredrik Jagenheim

Hi,

I have a application which recieves events asynchronously.

The event processing is done as such:

=09=09Thread.new do
=09=09=09ev =3D WIN32OLE_EVENT.new(@provider, '_IDataProviderEvents')
=09=09=09ev.on_event {|*args| event_handler(*args)}
=09=09=09ev.on_event("OnDataAvailable") { |datapacket| received(datapacket)=
}
=09=09=09loop do
=09=09=09=09WIN32OLE_EVENT.message_loop
=09=09=09=09sleep(0.1)
=09=09=09end
=09=09end

I have to use the sleep, or else the CPU runs at 100%. However, this
limits me to 10 messages/second, which may be more.

I'm experimenting with other values for sleep, but I have a feeling
there's a better way.

Can't I just ask message_loop to hang until there is a message?

//F
 

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,777
Messages
2,569,604
Members
45,221
Latest member
TrinidadKa

Latest Threads

Top