在长循环期间,Flex会等同于ProcessMessages和无响应的UI [英] Flex equivalent of ProcessMessages and unresponsive UI during long loops

查看:198
本文介绍了在长循环期间,Flex会等同于ProcessMessages和无响应的UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的Flex应用程序的UI在很长的处理循环(几十秒)期间变得没有反应。例如,当处理非常大的XML文件和每个元素做一些事情...

有没有相当于ProcessMessages?也就是说,一个调用会告诉Flex继续响应UI事件,即使在一些长循环的中间,这样的UI不会变得没有响应?

我知道Flex是单线程设计。这就是为什么我正在寻找像ProcessMessages()这样的一个函数,它允许单线程重入应用程序(如在VB中,或基于单线程消息循环的C ++应用程序)在长时间操作。

答案总结


  1. 在Flex中使用 HandleEvents() ProcessMessages()
  2. 使用某种回调机制来迭代地处理长计算进程的块,同时在块之间产生运行时间,从而使其能够响应,这是在长时间计算期间维持响应性UI的唯一方法。 b $ b
  3. 完成上述操作的方法是:


    1. 使用 enterFrame 事件只要Flex应用程序下面的Flashmovie图层刷新其帧(类似于20fps),就被调用。
    2. 使用定时器。
    3. 使用 UIComponent.callLater()哪个时间表工作要稍后完成。 (如文档: code>为稍后调用的函数排队。在屏幕的每次更新之前,Flash Player或AIR调用计划进行更新的函数的集合。

    4. 使用故意触发的鼠标/键盘事件来创建伪工作线程,如




    5. 如果还有其他建议,或者如果我遗漏了任何东西,请随时编辑这个(现在)的wiki片段。

      解决方案

      问题是Flash单线程,即直到部分代码正在运行,不能进行其他处理。你将需要将处理分解成更小的块,并执行这些块,比如在 enterFrame 事件。



      编辑:恐怕这个(或Simon's)的回答不会改变这个在AS3中不可行的事实。请阅读这篇文章,以获取有关此问题的更多信息。这篇文章还包括一个名为PseudoThread的简单库,它有助于执行长时间的背景计算。尽管如此,你仍然必须把问题分解成小块。


      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 something per-element...

      Is there an equivalent of "ProcessMessages"? That is, a call that would tell Flex to continue responding to UI events, even in the middle of some long loop, so that the UI doesn't become unresponsive?

      I'm aware Flex is single threaded by design. That's exactly why I'm looking for something like ProcessMessages() - a function that allows single-threaded reentrant applications (like in VB, or single-threaded message loop based C++ applications) to remain responsive during long operations.

      Summary of Answers

      1. There's no built-in function like HandleEvents() or ProcessMessages() in Flex.
      2. Using some sort of callback mechanism to iteratively process chunks of a long computation process, while yielding to the runtime between chunks, thus enabling it to be responsive, is the only way to maintain a responsive UI during long computations.
      3. Ways of accomplishing the above are:

        1. Using the enterFrame event, which is called whenever the Flash "movie" layer below the Flex application refreshes its frame (which is something like 20fps).
        2. Using a timer.
        3. Using UIComponent.callLater() which schedules work to be done "later". (as the docs say: Queues a function to be called later. Before each update of the screen, Flash Player or AIR calls the set of functions that are scheduled for the update.
        4. Using intentionally triggered mouse/keyboard events to create pseudo "worker threads", as in this example.

      If there are further suggestions, or if I left out anything, please feel free to edit this (now) wiki piece.

      解决方案

      The problem is that Flash is single threaded, i.e. until a part of the code is running, no other processing can be made. You'll somehow need to break up the processing into smaller chunks and execute these chunks, say, on the enterFrame event.

      Edit: I'm afraid that downvoting this (or Simon's) answer does not change the fact that this is not doable in AS3. Read this article for more insight on the problem. The article also includes a simple "library" called PseudoThread, which helps in executing long background computations. You still have to break up the problem into smaller pieces yourself, though.

      这篇关于在长循环期间,Flex会等同于ProcessMessages和无响应的UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆