timerExec problem in dwt-win

torhu no at spam.invalid
Sat Sep 27 07:22:24 PDT 2008


This test doesn't print "OK" like I think it should, it just prints 
"ctor called".  It seems that timerExec doesn't work when called from 
other threads than the GUI thread.  The SWT docs seem to say that this 
should work.  Am I doing something wrong?

When doing the same thing in my real DWT app, I get an "Invalid thread 
access" exception, but I haven't put an exception handler into the 
secondary thread in this sample.

---
module timertest2;

import dwt.DWT;
import dwt.dwthelper.Runnable;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.Button;
import dwt.widgets.Text;

import tango.core.Thread;
import dwt.events.SelectionListener;
import dwt.events.SelectionEvent;
import tango.util.log.Trace;


void main()
{
     try {
         Display display = new Display();
         Shell shell = new Shell(display);
         shell.setSize(300, 200);
         shell.setText(__FILE__);
         auto btn = new Button( shell, DWT.PUSH );
         btn.setBounds(40, 50, 100, 50);
         btn.setText( "test timerExec" );

         auto txt = new Text(shell, DWT.BORDER);
         txt.setBounds(170, 50, 100, 40);

         auto t = new Thread({Display.getDefault.timerExec(500, new 
class Runnable {
             this() { Trace.formatln("ctor called").flush; }
             void run() { Trace.formatln("OK").flush; 
txt.setText("timerExec OK"); }
         });});

         btn.addSelectionListener(new class () SelectionListener {
             void widgetSelected(SelectionEvent event) { t.start(); }
             void widgetDefaultSelected(SelectionEvent event) { }
         });

         shell.open();
         while (!shell.isDisposed()) {
             if (!display.readAndDispatch()) {
                 display.sleep();
                 Trace.format(".").flush;
             }
         }
     }
     catch (Exception e) {
         Trace.formatln(e.toString);
     }
}
---


More information about the Digitalmars-d-dwt mailing list