软硬度:寻找设计模式来显示忙碌光标,而我的应用程序是与QUOT;忙QUOT;我的、光标、软硬、应用程序

2023-09-09 21:53:39 作者:不打扰是莪最后的温柔

我有一个Flex 4应用程序,现在,然后需要做大量的处理,这会导致用户等待几秒钟就完成。我知道的Flex允许一个设置,并通过光标经理删除忙光标。我使用它,如下所示:

I have a Flex 4 app that now and then needs to do a lot of processing, which causes a user to wait a few seconds for it to complete. I know Flex allows one to set and remove busy cursors via the cursor manager. I'm using it as follows:

CursorManager.setBusyCursor();    // add busy cursor
// execute lengthy processing here; e.g. switch to a new screen with a lot of layout
CursorManager.removeBusyCursor(); // remove busy cursor

然而,在实践中,在某些情况下,忙状态光标不显示,或者,如果显示,它会显示它就会被删除之前(如果你眨眼,你会错过它)。我们的想法是,而过长的处理发生,而不是用于第二它完成后的一小部分,以具有繁忙光标显示

However, in practice, for certain situations, the busy cursor doesn't display, or, if it displays, it displays just before it gets removed (if you blink you'd miss it). The idea is to have the busy cursor display while the lengthly processing occurs, not for a fraction of a second after it completes.

所以,我不知道是否有一种设计模式,我可以使用,以确保忙光标总是显示之前执行过长的处理步骤。例如,这些处理步骤可以是:(1)转换到一个新的屏幕,必须建立,其具有复杂的布局,或(2)创建一个图表,需要很长的时间来呈现等

So, I'm wondering if there's a design pattern I can use to make sure the busy cursor is always displayed BEFORE executing the lengthly processing steps. For example, these processing steps could be: (1) transitioning to a new screen that must be built, which has a complex layout, or (2) creating a chart that takes a long time to render, etc.

我怀疑有人在Flex的设计已经在同一时间或其他运行到这一点。是否有一个通用的设计模式可以使用,或者是一个独特的冒险每次弄清楚哪儿来执行忙光标,以便它在正确的时刻显示?任何意见AP preciated。

I suspect anyone designing in Flex has run into this at one time or another. Is there a general design pattern one can use, or is it a unique adventure each time to figure out where exactly to execute the busy cursor so that it displays at the right moment in time? Any advice appreciated.

推荐答案

您的问题是,任何一种漫长的处理将冻结UI,使其不会得到一个机会来更新屏幕上 - 因此不显示任何光标改变之前开始计算。

Your problem is that any kind of "lengthy processing" will freeze the UI, so that it will not get a chance to update the screen - and therefore not show any cursor changes prior to starting the calculation.

有几个你可以做的事情,但在我们进入细节:当然,这将是最好保持冻结发生在首位!您可以通过以下两种方法之一:改变你的计算以这样一种方式,你可以优化你的算法,足以使他们能够完成的速度比当前帧速率,或分解再计算成小块,因此S preading资源跨越多个帧密集环 - 和允许屏幕之间更新。您可以在当前FP版本使用工人为,或伪线程的在旧的。

There are a couple of thing you can do, but before we get into details: Of course it would be best to keep freezes from happening in the first place! You can do this in one of two ways: Change your calculations in such a way that you either optimize your algorithms enough so that they can complete faster than the current frame rate, or break down longer calculations into smaller chunks, thus "spreading" resource intensive loops across multiple frames - and allow the screen to update in between. You can use workers for that in the current FP version, or pseudo threads in older ones.

有关立竿见影的效果,只需100毫秒使用的setTimeout 推迟重过程,的在的改变光标。这样一来,屏幕可以更新之前的计算开始。

For quick results, just delay the heavy process by 100ms using setTimeout, after changing the cursor. That way, the screen can update before the calculations start.