Flex:寻找设计模式以在我的应用程序“忙碌"时显示忙碌的光标 [英] Flex: Looking for design pattern to display busy cursor while my app is "busy"

查看:24
本文介绍了Flex:寻找设计模式以在我的应用程序“忙碌"时显示忙碌的光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 中进行设计的人都曾遇到过这种情况.是否有一个可以使用的通用设计模式,或者每次找出执行繁忙光标的确切位置以便它在正确的时间显示时是否每次都是一次独特的冒险?任何建议表示赞赏.

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.

您可以做几件事,但在我们详细介绍之前:当然,最好首先防止发生冻结!您可以通过以下两种方式之一执行此操作:以这样一种方式更改您的计算:您可以充分优化您的算法,以便它们可以比当前帧速率更快地完成,或者将较长的计算分解成更小的块,从而分散"资源跨多个帧的密集循环 - 并允许屏幕在两者之间更新.您可以在当前 FP 版本中使用 workers,或旧线程中的伪线程.

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.

为了快速获得结果,只需使用 setTimeout 将繁重的过程延迟 100 毫秒, 更改光标之后.这样,屏幕可以在计算开始之前更新.

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.

这篇关于Flex:寻找设计模式以在我的应用程序“忙碌"时显示忙碌的光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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