Flex equivalent of ProcessMessages and unresponsive UI during long loops

前端 未结 5 2276
陌清茗
陌清茗 2020-12-17 19:00

I find that my Flex application\'s UI becomes unresponsive during very long processing loops (tens of seconds). For example, while processing very large XML files and doing

5条回答
  •  星月不相逢
    2020-12-17 19:52

    I can tell you definitively that as of Flex 3, there is no built-in construct similar to the ProcessMessages functionality you are describing.

    The most common way to work around this is to split whatever work you are processing into a queue of "worker" tasks and a "worker manager" to control the queue. As each "worker" completes its processing, the worker queue manager pops the next worker off the queue and executes it in a callLater() invocation. This will have an effect that is similar to "yielding to the main thread" and allow your UI to receive events and be responsive, while still allowing the processing to continue when control is returned to the worker.

    Once you've got this working, you can do some testing and profiling to figure out if your application can get away with executing a run of multiple workers before invoking callLater(), and encapsulate this logic within the worker queue manager. For example, in our implementation of this pattern (with a few hundred workers in the queue), we were able to get the processing done more quickly with a comparable perceived performance by executing 4 workers before "yielding to the main thread" with callLater(), but this is totally dependent on the scope and nature of the work that your workers are doing.

提交回复
热议问题