First, please forgive me if I'm seeming critical, but I believe you are
complicating the issue unnecessarily by having two apps.

The problem is that you're using a loop of some kind that doesn't terminate
within say, 5 seconds (even 1 second is way too long). by putting this loop
in a different app it works on IE because you have a hyperthreaded or dual
core system and it multithreads it appropriately.

The real solution is to rewrite your loop.

For example

 

While(shouldprocess==true) {

Dosometask();

}

 

Is bad practice ;)

 

Instead try something like

Var intervalname;

Function processChunk(data) { 

If(shouldprocess!=true) { clearInterval(intervalname); return; }

..

 

 }

Intervalname =  setInterval(processChunk,10);

 

This will then run as close to 100 times a second as possible, and yield its
processing thread so the system doesn't lock.

Good luck,

 

Seth

 

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Aldo Bucchi
Sent: Monday, November 19, 2007 1:58 PM
To: [email protected]
Subject: [flexcoders] Emulating Flash MultiThreading; Approaches

 

Hi Guys,

I need to run an expensive computation in the background ( 2 seconds
on a modern day laptop ) while keeping the UI responsive. For this
matter I have tried creating a secondary application and communicate
with it in a non-blocking way. I share my thoughts so far to see if
anyone can help with this one.

First, some approaches to create a secondary application:
* Load a module at runtime
* Publish a module from within a new Frame ( Gonzalez/Harui trick )
* Open another SWF altogether ( seems the safest best bet to me )

Some approaches to communicate between apps:
* LocalConnection ( sync )
* Write/Poll a LSO ( async )

And to go from blocking to non-blocking communication ( maybe )
* Upon receiving a call start a timer and listen for the completion
event. This should make the call return while leaving it up to events
to start the real processing.

Now, I haven't tried every combination yet, but so far I found some
interesting results:

I created two separate applications that talk through a
LocalConnection. They use the timer trick ( upon receiving a call they
set up a very short internal timer that will eventually start internal
execution of the code ). If I open both SWFs in IE they effectively
work as expected. I can start a very heavy computation on the
secondary app while the first remains totally responsive to user
events. Then I can make a reverse call and pass the results back. So
far so good :)

Firefox, however, is a show killer. No matter how I open the two apps
( tabs, apps, etc ) blocking occurs.

Can someone from the flash player shed some light on this?
This is not real multi-threading, it is simpler in the sense that I
don't need synchronization. The contract is passing an input and
waiting for a result.

Now, even if I managed to pull this off with parallel applications...
how would I materialize that setup in AIR?

Thanks,
Aldo

-- 
:::: Aldo Bucchi ::::
+1 858 539 6986
+56 9 8429 8300
+56 9 7623 8653
skype:aldo.bucchi

 

Reply via email to