ProgressMonitorDialog : Access Violation

Frank Benoit keinfarbton at googlemail.com
Sat Jun 21 06:35:33 PDT 2008


Frank Benoit schrieb:
> i had tested it with dmd 1.031 ... and indeed with dmd 1.028 it crashes.
> Your first example code should work now.
> With the
>  > dialog.run(false, true, dgIRunnableWithProgress(&run));
> there is still a problem :/

Now it works with fork=false, but another anon class workaround was 
necessary.

Also a fix in the example code is needed to make fork=false work. From 
the ProgressMonitorDialog doc:
If fork is set to false, the runnable will run in the UI thread and it 
is the runnable's responsibility to call Display.readAndDispatch()  to 
ensure UI responsiveness.

The example code looks now like this:

import dwt.DWT;
import dwt.layout.FillLayout;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.Listener;
import dwt.widgets.Event;
import dwt.widgets.Button;

import dwtx.jface.dialogs.PopupDialog;
import dwt.dwthelper.utils;

import dwtx.jface.dialogs.ProgressMonitorDialog;
import dwtx.core.runtime.IProgressMonitor;
import dwtx.jface.operation.IRunnableWithProgress;

import tango.core.Thread;

version=NOFORK;

void handleSelection(Event e, Shell shell) {
     void run(IProgressMonitor monitor) {
         monitor.beginTask("generate", 30);
         for(int i=0; i<100; i++) {
             if(monitor.isCanceled()) {
                 return;
             }
             monitor.worked(1);
             Thread.sleep(0.050);
             version(NOFORK) Display.getCurrent().readAndDispatch();
         }
         monitor.done();
         version(NOFORK) Display.getCurrent().readAndDispatch();
     }
     auto dialog = new ProgressMonitorDialog(shell);
     version(NOFORK) {
         dialog.run(false, true, dgIRunnableWithProgress(&run));
     } else {
         dialog.run(true, true, dgIRunnableWithProgress(&run));
     }
}

void main() {
     final Display display = new Display();
     final Shell shell = new Shell(display);
     shell.setLayout(new FillLayout());
     Button button = new Button(shell, DWT.PUSH);
     button.setText("&OK");

     button.addListener(DWT.Selection,
         dgListener(&handleSelection, shell));

     shell.pack();
     shell.open();
     while (!shell.isDisposed()) {
         if (!display.readAndDispatch()) display.sleep();
     }
     display.dispose();
}



More information about the Digitalmars-d-dwt mailing list