Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Losing SyncExec events?
Losing SyncExec events? [message #505336] Tue, 29 December 2009 16:51 Go to next message
Robert Craig is currently offline Robert CraigFriend
Messages: 7
Registered: December 2009
Junior Member
I've been dealing with a strange issue with syncExec calls.
I've produced a small code sample included that shows the problem.

The code example opens a shell and has two back-to-back syncExec calls running in a different thread (the execution of which is shown on the console output).

With the mouse on the shell, everything works just fine. If you move the mouse off of the shell, the syncExec's stop executing. My guess is that I'm overrunning the internal event queue, but I'm not sure that I understand how that could be given that the syncExec is supposed to be... well... synchronous (so there shouldn't be more than one sync exec event on the queue at a time)

Couple of things to note: It requires two sync execs in the loop (my original program has something happening in-between which is of indeterminate length). Adding in a sleep (commented out in the sample) appears to fix the problem.

This is with the 3.5.1 SWT release.

Thanks for any pointers!
Rob.


import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Testsync {


int count;
public class Syncer extends Thread {
public void run() {
count = 0;
while (true) {
if (!display.isDisposed()) {
display.syncExec(new Runnable() {
public void run() {
System.out.println("execed ");
}
});
}
/* try {
Thread.sleep(10);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
*/
if (!display.isDisposed()) {
display.syncExec(new Runnable() {
public void run() {
System.out.println("execed " + count++);
}
});
}

try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

Display display;
Syncer syncer;

public Testsync() {
syncer = new Syncer();
display = new Display();
}


public static void main(String[] args) {

final Testsync testsync = new Testsync();
Shell shell = new Shell (testsync.display);
testsync.syncer.start();
shell.setSize(500,500);
shell.open();
while (!shell.isDisposed()) {
if (!testsync.display.readAndDispatch())
testsync.display.sleep();
}

}

}
Re: Losing SyncExec events? [message #505863 is a reply to message #505336] Tue, 05 January 2010 12:09 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
Which platform you are on ? This works for me on Ubuntu., I can see the
runnable in syncExec is executed irrespective of the mouse position.
Re: Losing SyncExec events? [message #507004 is a reply to message #505863] Mon, 11 January 2010 16:34 Go to previous messageGo to next message
Robert Craig is currently offline Robert CraigFriend
Messages: 7
Registered: December 2009
Junior Member
Good to know that this is supposed to work Smile .
I'm running this on Windows Vista with SWT 3.5.1.

Thanks for looking!
Robert.
Re: Losing SyncExec events? [message #507031 is a reply to message #507004] Mon, 11 January 2010 17:43 Go to previous messageGo to next message
Dilton McGowan II is currently offline Dilton McGowan IIFriend
Messages: 110
Registered: July 2009
Senior Member
On Mon, 11 Jan 2010 11:34:56 -0500, rcraig wrote:

> Good to know that this is supposed to work :) . I'm running this on
> Windows Vista with SWT 3.5.1.
>
> Thanks for looking!
> Robert.

You should file a bug if one does not exist already:
https://bugs.eclipse.org/bugs
Re: Losing SyncExec events? [message #507048 is a reply to message #507031] Mon, 11 January 2010 14:42 Go to previous messageGo to next message
Dilton McGowan II is currently offline Dilton McGowan IIFriend
Messages: 110
Registered: July 2009
Senior Member
On Mon, 11 Jan 2010 17:43:02 +0000, Dilton wrote:

> On Mon, 11 Jan 2010 11:34:56 -0500, rcraig wrote:
>
>> Good to know that this is supposed to work :) . I'm running this on
>> Windows Vista with SWT 3.5.1.
>>
>> Thanks for looking!
>> Robert.
>
> You should file a bug if one does not exist already:
> https://bugs.eclipse.org/bugs

PS Your sample code works on XP unless I don't understand the symptoms.
Re: Losing SyncExec events? [message #507061 is a reply to message #507048] Mon, 11 January 2010 21:14 Go to previous messageGo to next message
Robert Craig is currently offline Robert CraigFriend
Messages: 7
Registered: December 2009
Junior Member
Just filed a bug report. I wanted to make sure that I wasn't doing anything obviously wrong first.

I just tried my code under XP and it does indeed work as expected (and it still fails under Vista). This seems to be a Vista specific issue...

Thanks!
Rob.
Re: Losing SyncExec events? [message #507076 is a reply to message #507061] Mon, 11 January 2010 22:41 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
just out of curiosity I tested Your code under Vista Home Premium SP2
and I got an even stranger behavior:

The program works Ok (continuous printouts) IFF the Shel *does not* have
focus.

If the Shell has focus I hav printouts only if I *move* the mouse over
it; i.e.: if the mouse is outside I have no printouts, if the mouse is
still I have no printouts.

Curiouser and curiouser :)

Regards
Mauro
Re: Losing SyncExec events? [message #507243 is a reply to message #507076] Tue, 12 January 2010 15:35 Go to previous message
Robert Craig is currently offline Robert CraigFriend
Messages: 7
Registered: December 2009
Junior Member
Curiouser and curiouser indeed. I don't have to move the mouse on the shell if it has focus to get it to work , but I DID notice that if the shell doesn't have focus, things seems to work properly. As soon as I give it focus and move the mouse away, it stops...

At least you've confirmed for me that there's definitely something odd happening :>.

Thanks!
Rob.
Previous Topic:Problem in SWT Text widget and Mac
Next Topic:Tip for Correct implementation to anchor a widget in the parent composite rectangle.
Goto Forum:
  


Current Time: Thu Dec 26 14:34:47 GMT 2024

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

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

Back to the top