[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: SWT and network / socket data?
|
Use Display.syncExec. See:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet7.java?rev=HEAD&content-type=text/vnd.viewcvs-markup
"Sal Valente" <svalente@xxxxxxx> wrote in message
news:pan.2005.12.06.05.39.12.227974@xxxxxxxxxx
>I have an SWT program that displays a Label. Whenever the user selects a
> menu item, I want to display something in that label. Also, the program
> is listening for data on a Socket. Whenever network data arrives, I want
> to display it in the Label.
>
> So I've got two Threads. One is running the SWT main loop:
> while (!shell.isDisposed()) if (!display.readAndDispatch())
> display.sleep();
>
> The other is reading and processing data from the network socket.
>
> I don't think it's a good idea (or at all legal) for the second
> Thread to ever call label.setText(). I want to funnel all SWT calls
> through a single thread. Is there a way to do this, or, better
> yet, is there a "right" way to do this? (Is there a way for the network
> thread to add events to the end of the queue so that the SWT thread will
> get to them in their turn? Or a way for the network thread to
> wake-up the SWT thread?)
>
> Thanks.
>