2 Replies Latest reply on Dec 2, 2008 6:52 AM by kstephens2

    No locking disk recursion

      I am working on an AIR app in Javascript that needs to read the contents of an entire drive. I tried using the cookbook recursive function ( http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=4&postI d=9410 ) however, this causes the main thread to lockup and makes the program report as not responding to Windows.

      I need a method that includes some sort of setTimeout() to allow the main thread time to refresh windows and respond to the OS. Has anyone had a similar issue and have a clever method of recursing with a pause? Or a better way to read the disk contents?

      Thanks for any help you can provide.
        • 1. Re: No locking disk recursion
          anirudhs Level 2

          I have done something similiar. I basically hooked up directory.getDirectoryListingAsync() and callLater. You could use Alex Harui's PseudoThread ( http://blogs.adobe.com/aharui/2008/01/threads_in_actionscript_3.html) for a much cleaner way.

          The performance was decent and most importantly, the UI did not lock up. There should be only one outstanding call to getDirectoryListingAsync at a time. When the listing event fires, iterate through the list and when you encounter a folder, save an index to the position in the result and call a callLater to a function that does getDirectoryListingAsync on that folder. When that completes, go back to the saved index and do the same for subsequent folders.
          • 2. Re: No locking disk recursion
            kstephens2 Level 1
            Thanks for your advice.

            I ended up doing a weird recursion that gave me speed and no lockup. The way it works is that I get the directory listing and loop through it in a while/shift loop pushing files into a tmp file. When I hit a directory I stop the while loop and call setTimeout to run this method for the subdirectory on and on in a recursive pattern. Then I jump back to the parent directory while loop and take off where I left off.

            This is a bit screwy but it works well for the fact I get the speed of the while loop but enough pause in the thread with setTimeout to refresh windows. I looked into the getDirectoryListingAsync but I really wanted to read things in a tree order and Async couldn't guarantee they would be written into the tmp file in a tree order, plus my method guarantees only one thing writing to the tmp file at a time.