5 Replies Latest reply on Aug 25, 2007 9:14 AM by ntsiii

    Handling long tasks

    Yann Martel Level 1
      Hi,
      I wanted to know what's the best way to handle long tasks in Flex.

      In my application, I have a heavy function that processes lots of data from an XML file. When this function is called, the whole app freezes. Even the busyCursor freezes and stop turning, and I get the OS cursor for non-responsive application (on MacOSX a multi-colored turning wheel).

      Is there a way to prevent such problems ?
        • 1. Re: Handling long tasks
          JKohn99 Level 1
          Flex is single threaded so you cannot move heavy tasks into a background thread
          like you can in Java. In reality Flex is for the presentation tier not for the server tier. It sounds like you are doing a bit of server processing on the client.

          There may be more options if using the Air runtime. In particular you could check out artemis ( http://artemis.effectiveui.com/) which is supposed to give you access to Java from Flex (via the air runtime). Of course all of this is still beta or alpha.
          • 2. Handling long tasks
            levancho Level 3
            there was a Interesting Topic about it here, and guys cam eup with some interesting Ideas, one of them was to let other swf do it for you with LocalConnection basically utilizing Browsers multi threading capabilities.
            take a look at this :

            thread 1

            and
            this
            thread 2
            • 3. Re: Handling long tasks
              ntsiii Level 3
              We were brainstorming on that one. I don't know for sure if our theory would even work.

              If you need to keep the task on the client, you can help things by breaking the task up using calllater. this will at least let the UI update, while the precess is running.

              Also, be aware that there is a 60 second limit on how long a script can run before a continue dialog is displayed. It can be made shorter, but not longer.

              Tracy
              • 4. Re: Handling long tasks
                Yann Martel Level 1
                I didn't know about callLater, sounds interesting. I'll try that, thanks.

                For the LocalConnection, it seems a bit complicated but interesting. The idea is to create an AS2 swf to do the calculations and get the result via LocalConnection. I have two questions about it:
                - I'm creating an AIR app, would I still be able to use it ? The goal is to use the multi-threading capabilities, so it shouldn't work in AIR, right ?
                - I thought that AS2 was something like 10 times slower than AS3, so I find it weird to use it to do heavy calculations. I've probably misunderstood something :)
                • 5. Re: Handling long tasks
                  ntsiii Level 3
                  AIR might give you other options, I haven't thought about that yet.

                  Yes, AS2 is slower than AS3 (I found 30%-40% in heavy, non-ui rendering calculations), but the goal is to find a way to offload the calculation from the main thread, so the speed difference is irrelevant.

                  AIR might let you do the same thing somenow with as3 code.
                  Tracy