axaptax++dynamics-ax-2012dynamics-ax-2009dynamics-365-operations

Dynamics AX x++ can't close first form


I see a strange case when open form twice using FormRun


    static void Job780(Args _args)
    {
        FormRun formRun;
        Args args = new Args();
        ;

        args.name(formstr(Form1));

        formRun = ClassFactory.formRunClass(args);

        formRun.init();
        formRun.run();
        formRun.wait();
    }

If I run this code twice then I see 2 forms but I can't close first form before I close the second.

I tried it on several instances, and different versions (2009, 2012). Cleared cache and *.auc fiels. Same result.

The question is how to fix it. I mean how to make form to be closed properly in any order. Thanks.


Solution

  • It is because you are using formRun.wait();.

    Use either formRun.wait(); if you want to stop execution until the form is closed.

    Or use formRun.detach(); if you want to let the form run separately.