Bug 4476 - No syncExec runnables run during scrolling (1FMGG2X)
Summary: No syncExec runnables run during scrolling (1FMGG2X)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P4 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-11 14:17 EDT by Mike Wilson CLA
Modified: 2002-05-16 11:43 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Wilson CLA 2001-10-11 14:17:26 EDT
When scrolling a slider for example, it is not possible to syncExec runnables from 
any other thread and have them run until the scroll thumb is released.  This means users
can not write code to respond to slider events during scrolling, nor can they do any 
other work on widgets created in that thread, assuming that most calls through AWT use
syncExec.

It appears that the OS creates a separate loop to read and dispatch events during scrolling and 
our (AWT) readAndDispatch loop waits, as a side effect of waiting runAsyncMessages is not called 
during this time.  We made a quick hack to post a special message to ourselves whenever a new 
syncExec runnable was added and when the windowProc saw that message it would run one async
runnable, this gave acceptable behaviour (we are not saying it is any sort of solution).

NOTE: Scrolling is ONE example of this problem.

NOTES:

	SN (5/16/00 3:42:38 PM)
		There is a problem doing this in VA/Java because "no context switch in call-in" which means
		that we can't signal the other thread that the work is done.  There is no way for me to easily
		test that my code is working.

	SN (5/16/00 6:20:08 PM)
		Can you elaborate on the other cases?

	SSQ/MVM (5/17/00 11:15:18 AM) -
		We can test the fix and you could wrap the code in a isVAJava flag or something. 
		In our case, we are not context switching, we are running a async runnable in the
		call in thread.

		ANOTHER CASE:
		If full window drag is ON and you have a window that paints itself (non native widgets), it
		will not paint. For example, run AwtClock and move it off the screen or move a window
		created with the same SWT display over it.
		
SN (5/17/00 3:34:32 PM)
	Ok, I will add a special flag that will default to false in VA/Java that will post
	a special message to wake up the event loop.  I look for this special message
	and run sync/async messages.

	SSQ to write a wad of code that shows the problem.

SSQ (5/18/00 10:45:02 AM) -
	The test case below shows the scrolling problem and the redrawing problem.	

import com.ibm.swt.*;
import com.ibm.swt.widgets.*;
import com.ibm.swt.graphics.*;

public class SyncProblem {

public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setBounds(0, 0, 200, 200);
	final Slider slider = new Slider(shell, SWT.HORIZONTAL);
	slider.setBounds(0, 150, 190, 25);
	final Label label = new Label(shell, SWT.HORIZONTAL);
	label.setBounds(0, 130, 190, 30);
	
	new Thread() {
		public void run() {
			while (!shell.isDisposed()) {
				shell.getDisplay().syncExec(new Runnable() {
					public void run() {
						GC gc = new GC(shell);
						gc.setBackground(new Color(shell.getDisplay(), 255, 0, 0));
						gc.fillRectangle(0, 0, 100, 100);
						gc.dispose();
					}
				});
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {}
			}
		}
	}.start();
	
	
	new Thread() {
		public void run() {
			while (!shell.isDisposed()) {
				shell.getDisplay().syncExec(new Runnable() {
					public void run() {
						label.setText("" + slider.getSelection());
					}
				});
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {}
			}
		}
	}.start();
	
	shell.setVisible(true);
	
	while (!shell.isDisposed()) {
		if (!shell.getDisplay().readAndDispatch ()) shell.getDisplay().sleep ();

	}
	System.exit(0);
}

}

	SN (2/1/01 2:44:24 PM) -
		We can fix this now that we run the C DLLs everwhere.
		SN to investigate if it is still wanted.
Comment 1 DJ Houghton CLA 2001-10-29 16:16:06 EST
PRODUCT VERSION:

SWT 032

Comment 2 Steve Northover CLA 2002-05-15 21:33:50 EDT
Fixed > 20020510.
Comment 3 Mike Wilson CLA 2002-05-16 11:08:05 EDT
Are we sure that this is not breaking anyone? Did you describe the 
change on the mailing list (and newsgroup?)? Is it possible that WSAD, 
for example, could get burned by this?
Comment 4 Steve Northover CLA 2002-05-16 11:43:50 EDT
I cleared this with Nick.  I put print when this was happening and it occurred 
never when scrolling and rarely when a menu was pulled down.  This behavior is 
already happening on every other platform.  The change has also been in for 
over two weeks now.

I case it wasn't clear, this was a dup but the problem still occurs in WinCE so 
I couldn't close the original.