Timer in DWT?

Frank Benoit keinfarbton at googlemail.com
Mon Sep 8 21:19:45 PDT 2008


Sam Hu schrieb:
> Thanks BB,now it works when the run() method is invoked in the InitializeComponents() method,but it does not work when invoked in the ctor.How come? Thanks,Sam
> 
> class MainForm:Runnable
> {
>   private:
>   Display display;
>   Shell shell;
>   Canvas canvas;
>   void InitializeComponents()
>   {
>    display=new Display;
>    shell=new Shell(display);
>    canvas=new Canvas(shell,DWT.NONE);
>    canvas.addPaintListener(new class PaintListener{
>     public void paintControl(PaintEvent e)
>     {
>        auto layout=new Locale;
> 
>      e.gc.drawText(layout("{:dddd,dd MMMM yyyy HH':'mm':'ss z}",
>                                 WallClock.now),100,100);
>    }});
>    run;
>    shell.open;
>   while(! shell.isDisposed)
>  {
>     if(! display.readAndDispatch)
>     display.sleep;
>  }
>   display.dispose;
>  }
>  public:
>   this()
>   {
>     InitializeComponents;
>     run;//invoke run() method here does not work?
>   }
>  void run()
>   {
>      canvas.redraw;
>      display.getCurrent.timerExec(1000, this);
> 
>   }
> 
> }
> int main(char[][] args)
> {
>  MainForm mainForm=new MainForm;
>  return 0;
> }
> 

the call to run() in the ctor is not executed, because the program is
hanging in the InitializeComponents() while loop. Only if the window is
closed, the loop is left and then the run is called ... too late.


More information about the Digitalmars-d-dwt mailing list