BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-28-2009, 09:23 PM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: OPTUS
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Issue with running a new Thread

Please Login to Remove!

Hi there,

I was hoping someone could help with a seemingly easy task - but one I can't
figure out!!

I am trying to run some code in my app that goes out & check whether there
is a later version of the software available.

I am running it in a new thread, using the code below. The code fires when the main screen of the app is displayed. The code "works", but
when I run it the screen locks up till the operation is completed. I had
thought by having it in its own Thread that it wouldn't impact the screen (ie I still scroll around the screen).

Does anyone have an idea as to what might be wrong (or a better way to do it)??

Cheers
Shane


------------------------

protected void onDisplay(){

super.onDisplay();

Thread t1 = new Thread(new Runnable() {
public void run() {


UiApplication.getUiApplication().invokeLater(
new Runnable()
{
public void run()
{
UpdateStatusBar("Checking for latest version");
CheckVersion();
UpdateStatusBar("Monitoring . . .");
}
}
);
}
});
t1.start();

}
*/
Offline  
Old 05-28-2009, 09:55 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Quote:
Originally Posted by bimetrix View Post
Hi there,

I was hoping someone could help with a seemingly easy task - but one I can't
figure out!!

I am trying to run some code in my app that goes out & check whether there
is a later version of the software available.

I am running it in a new thread, using the code below. The code fires when the main screen of the app is displayed. The code "works", but
when I run it the screen locks up till the operation is completed. I had
thought by having it in its own Thread that it wouldn't impact the screen (ie I still scroll around the screen).

Does anyone have an idea as to what might be wrong (or a better way to do it)??

Cheers
Shane


------------------------
Code:
protected void onDisplay(){
           
         super.onDisplay();

            Thread t1 = new Thread(new Runnable() {  
                public void run() {
                    
                        
                    UiApplication.getUiApplication().invokeLater(
                    new Runnable()
                        {
                            public void run()
                            { 
                                UpdateStatusBar("Checking for latest version");
                                CheckVersion();
                                UpdateStatusBar("Monitoring . . .");          
                            }
                    }
                    );
                }
            });
            t1.start();  
       
    }
*/

Please read the sticky thread on posting code.

UiApplication.getUiApplication().invokeLater(...) IIRC causes it's runnable to be run on the main event thread. Try removing that and just have your three calls in your thread run method.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 05-29-2009, 08:14 AM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Now that I'm back in the office, I can confirm what I said above.

But please do read this thread: How to paste 100% FORMATTED Source Code In Your Forum Posts

It is so much easier to take in the structure of code if it is formatted the way we have all come to expect.

In any case try something like this:

Code:
protected void onDisplay(){
           
         super.onDisplay();

            Thread t1 = new Thread(new Runnable() {  
                public void run() {
                    UpdateStatusBar("Checking for latest version");

                     CheckVersion();

                     UpdateStatusBar("Monitoring . . .");          
                }
            });

            t1.start();  
    }
If your UpdateStatusBar method does not hold the event lock, you should surround the calls to it in the thread with synchronized(UiApplication.getEventLock()) like this:

Code:
protected void onDisplay(){
           
         super.onDisplay();

            Thread t1 = new Thread(new Runnable() {  
                public void run() {
                    synchronized(UiApplication.getEventLock()) {
                        UpdateStatusBar("Checking for latest version");
                     }

                     CheckVersion();

                    synchronized(UiApplication.getEventLock()) {
                        UpdateStatusBar("Monitoring . . .");
                     }
                }
            });

            t1.start();  
    }
__________________
My other Blackberry is a PlayBook.
Offline  
Old 05-31-2009, 09:51 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: OPTUS
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for that!!

And thanks for the heads up on posting code examples. Will make sure that they are formatted correctly next time.

Cheers
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.