开发者

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

开发者 https://www.devze.com 2023-01-26 12:17 出处:网络
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 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


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.


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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消