Thank you for visiting the BlackBerry Support Community Forums.
BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)
BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.
"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."
- Kevin Michaluk, Founder, CrackBerry.com
Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.
07-05-2009 12:31 PM
I have an app that makes updates to the UI by passing in a reference for a bitmapfield to a new thread, and that thread updates the UI.
The problem I am having is that I want the main thread "wait" for the sub-thread to update the graphics, before proceeding with the "game".
so.... for example..
// update the main bitmapfield
pt = new PlayerThread(bfField,square); pt.start();
// wait for the thread to finish updating the ui
Now, I *KNOW* this is not the proper way to do this, because the UI does not get updated, since the UI is in a loop waiting for the thread to finish, which defeats the purpose of having the thread in the background in the first place.
What is the "correct" wait to do this? Have I completely missed the point of threading?
This works fine if I don't "wait" for the thread,but it means the user can press buttons, or interact with the game when they aren't supposed to.
I was thinking there must be a way to set a "isthreading = true" var, and disable button presses by adding an if to my keydown, but how can i make my app "wait" for the thread i created to be finished, but not actually pause the UI itself?
Hopefully that was clear...
Solved! Go to Solution.
07-05-2009 12:34 PM - edited 07-05-2009 12:39 PM
I just noticed Thread.yield(); ...
is that the proper way? ... edit, this has the same effect as the while loop..
07-05-2009 01:27 PM
You need a notification mechanism that tells the UI thread "I'm done" or "data is ready". Never loop in a UI thread - this will eventually cause the event queue to overflow, resulting in you application being dumped out as "unresponsive".
A typical mechanism is to implement a listener and a data event. The "interested" party registers a listener with the background thread, the background thread fires the data event when appropriate.
If there is only one listener, then this can be implemented with less overhead by using a callback mechanism.
Look for references to the Observer pattern: