Days of lessons -lesson 2- Adobe Air and AV

Lesson 2 in my fortnight of not much fun, is to do with adobe AIR and file copying:

Problem: a download manager written for a client is hanging/erroring on making a duplicate of a recently downloaded file.

Now I did not get this problem on my dev machine, nor on my Linux box, or other Virtual machines, the error was our old fav #3128 found at runtime error messages and as the error suggest was caused by a combination of greedy AV process and churning HDD (actually the client machine was swapping due to low mem)

Sadly my initial hope to do it as Asynchronous action so as to not do nasty pauses by using a 1 off timer

SecondTimer = new Timer(500, 1);
SecondTimer.addEventListener(TimerEvent.TIMER, doSecondCopy );

this did not work because if there was a tiny file in the download sequence, the you could end up trying to copy the second file before the first one had been finished with by the AV, and due to the flow of the application a move to full Asynchronous behaviour was not practical.

so I ended up doing the old horror of inserting a pause in the app in flex/flash/air this is done like this

import flash.utils.getTimer;

var now:int = 0;
var start:int = getTimer();
while (start+500>now) {
now = getTimer();

for a 0.5 second pause

yes I know its bad, but it works, and I think its less ugly than multiple retrying after multiple tests for I/O errors. (ick)

Leave a Reply

Your email address will not be published.