Hi Trent,
I'm fairly certain there's nothing like the invokeLater() in the doja API. I
guess you've tried some kind of non-threadsafe method? You say you can't
safely update the UI from the HTTP thread. What's happening? blocking? I'm
no thread guru, so I really don't know. How about passing your HTTP thread a
reference to the UI button, so that it can call the setText() directly? or
maybe vice-versa, so the button can kill the HTTP thread.
Hope I didn't confuse you anymore. Let me know what you come up with, as I may
need it myself someday. Good luck!
--jason
--- Trent Hill <Trent.Hill@bullant.com.au> wrote:
> Hi Jason,
>
> > What exactly are you trying to do?
>
> It's quite simple really - my application has created a thread. Some time
> later, this thread needs to update the user interface eg. to change the text
>
> on a label. Now, as far as I know the nttdocomo.ui library is not thread
> safe
> ie. it is only safe to call Label.setText from the event handling thread. So
>
> I somehow need to execute the necessary code on the ui thread.
>
> If I were using C/Win32 I'd use PostMessage(...)
> If I were using Java/Swing I'd use SwingUtilities.invokeLater(...)
> If I were using Java/Midp I'd use Display.callSerially(...)
>
> I can find anything like this in the com.nttdocomo.ui library.
>
> > Can you give a pseudo-code example?
>
> Of course.. this is not my real application but here's a similar example:
>
> Imagine you had a ui with a button and a label. When the user clicks the
> button, a stock quote is downloaded from an HTTP server and displayed on
> the label.
>
> Now, the HTTP download is blocking and I do not want to block the main event
>
> handling thread while the download is occurring eg. I may want a cancel
> button to be available during the download attempt. Therefore, I must create
>
> a second thread to handle the HTTP download. When the download succeeds, I
> need to update the label from the event handling thread to be thread safe.
>
> So, in pseudo code:
>
> // Event handling thread:
> method handleEvent(event, arg)
> {
> if (event == buttonClick)
> {
> // create new thread to download quote
> new Thread(downloadQuote)
> }
> else if (event == dataReceived)
> {
> // display the new quote
> myLabel.setText(arg)
> }
> }
>
>
> // Network thread:
> method downloadQuote
> {
> openHttpConnection(myUrl)
> quote = downloadData() // <- long blocking operation
> closeHttpConnection()
>
> // somehow notify event handling thread since I cannot safely update
> // the ui from this thread
> sendMessage(handleEvent, dataReceived, quote) // *** <- how to do this??
> }
>
> I hope this makes some sense to you. Any assistance would be appreciated.
>
> Thanks, Trent.
>
> --
> Trent Hill
> Software Engineer
> Gravana Pty Ltd (trading as Bullant Software)
>
>
>
>
> This mail was sent to address jasonpollard@yahoo.com
> Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/
>
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
Received on Fri Jun 13 11:01:49 2003