Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT and network / socket data?
SWT and network / socket data? [message #465098] Tue, 06 December 2005 05:39 Go to next message
Sal Valente is currently offline Sal ValenteFriend
Messages: 2
Registered: July 2009
Junior Member
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.
Re: SWT and network / socket data? [message #465109 is a reply to message #465098] Tue, 06 December 2005 09:02 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Use Display.asynExec

Sal Valente wrote:
> 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.
>
Re: SWT and network / socket data? [message #465118 is a reply to message #465098] Tue, 06 December 2005 11:55 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Use Display.syncExec. See:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet7.java?rev=HEAD&am p;content-type=text/vnd.viewcvs-markup


"Sal Valente" <svalente@mit.edu> wrote in message
news:pan.2005.12.06.05.39.12.227974@mit.edu...
>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.
>
Previous Topic:[SWT][Draw2D] refresh problem
Next Topic:Menu in Composite
Goto Forum:
  


Current Time: Fri Mar 29 09:52:42 GMT 2024

Powered by FUDForum. Page generated in 0.02604 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top