Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN
Accepted Solution

Preventing the interface from hanging on an intensive function

Hi all!

 

I'm calling an intensive function(scans through all the contacts), and it hangs my user interface.

I tried to display a spinning wheel before the function starts, and hide it in the end, but it won't show up, and when it does, it imediately disappears again.

 

Any suggestions on how to solve this?

PS - in case it matter, the function is blackberry.pim.Contact.find()

Nuno
Trusted Contributor
Posts: 117
Registered: ‎02-29-2012
My Device: PlayBook & Nexus 4

Re: Preventing the interface from hanging on an intensive function

You can try using a Web worker.

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Preventing the interface from hanging on an intensive function

Agreed.  

 

Background:

Web pages are single-threaded by default.  Meaning any syncronous JavaScript that is executing will block UI, creating the illusion that your app is frozen.

 

Here is an example:

http://blackberry.github.com/WebWorks-Samples/kitchenSink/html/html5/workers.html

 

1) Press the "Begin (main thread)" button - see how you cannot interact with the input field or  buttons until the processing has completed?  This is because the JavaScript is being executed by the main thread and is blocking the UI.

 

2) Press the "Begin (web workers)" button.  All secondary processing is now occuring on separate threads, allowing your

users to continue interacting with the UI.

 

 

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Preventing the interface from hanging on an intensive function

Cool, never heard of WebWorker before.

Seems like it will solve the problem Smiley Happy

 

thanks!

Nuno