How to create a “Please Wait” spinner while data is being imported

天大地大妈咪最大 提交于 2019-12-12 05:49:49

问题


I am creating an Flex AIR app which imports data from a zip file into a sqlite db. I need to show a progress bar / "Please Wait" spinner animation so that the user waits till the operation completes.

I have tried to put a pop-up spinner animation but the problem is that the spinner stops spinning as soon as the database import queries start executing.

I need to run both the spinner code and the import code simultaneously rather than sequentially.

Thanks


回答1:


The problem you are facing here is because Flex is a single threaded application. When you run large amounts of as processing, the thread does not update the UI, so your spinner stops spinning.

I think you can work around this by creating a Green Thread to handle your processing code if it can be sliced down. You can check here for an as3 implementation of the Green Thread.

I can provide some more info on implementing it if you need.




回答2:


Your issue could be caused by the fact that Flash is single-threaded. Try replacing the import with at timer, to remove the cpu-intesive operation. It that proves not to be the issue, a bit of code could speed up debugging :)




回答3:


So - if you want just a spinner, you do not need any more data. If you want a progress bar, though, you will just have to know how much data is there (most likely the size of the zip will be precise enough). Then - have some Event.ENTER_FRAME listener in which you will take a part of the data, insert into table... And stop there. It will then show the animation of stuff. Try to see what amount of data is optimal... Most likely by adding a FPS meter there too, and if it goes too low, make the amount lower.

If you want the progress bar, just increment a variable with how many bytes were already parsed, and divide that by the total bytes - a ratio for progress bar. Rest same as spinner.



来源:https://stackoverflow.com/questions/4226399/how-to-create-a-please-wait-spinner-while-data-is-being-imported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!