System.InvalidOperationException. Use Form.ShowDialog Instead? - Forum - OpenEdge Development - Progress Community

System.InvalidOperationException. Use Form.ShowDialog Instead?

 Forum

System.InvalidOperationException. Use Form.ShowDialog Instead?

  • I have a .cls splash screen (splash.cls) which has a button which when clicked runs our .w tree menu structure (treemenu.w). This all works fine.

    I have the following code which runs a.cls file (aForm.cls) when double clicking an icon within our menu structure ....

    DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

    frm = NEW Cls.aForm().

    WAIT-FOR System.Windows.Forms.Application:RUN (frm).

    DELETE OBJECT frm.

    I then get the following error pop-up. System.InvalidOperationException. Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog() Instead.

    I'm aware the issue seems to be around having two cls files running as when I run aForm.cls without splash.cls running, aForm.cls runs fine. I'm just wondering how I go about using Form.ShowDialog and where?

    I hope I've managed to make some sense here, I've attached some screenshots as well.

    Any help would be greatly appreciated.

    Thanks, Dez

    Screenshots.doc

  • The rule is: One World, One WAIT-FOR..

    The piece of code that invokes the splash.cls must have a WAIT-FOR System.Windows.Forms.Application:RUN() which is the only WAIT-FOR that you should have. Delete the WAIT-FOR in your tree menu program.

  • Hi Kevin,


    If I remove the wait-for from the .w tree menu the menu closes as soon as it opens


    Thanks, Dez

  • Hi Derek,

    did you delete the line "DELETE OBJECT frm." in your tree menu program aswell?

    Regards, Marko

  • sorry double posted

  • I don't think I've made myself clear sorry.


    When I'm double clicking on the icon "run cls file" in the tree menu (see screenshot from first post) it is in affect running a .p called runner.p which calls aForm.cls. It is this file that contains....


    DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

    frm = NEW Cls.aForm().

    WAIT-FOR System.Windows.Forms.Application:RUN (frm).

    DELETE OBJECT frm.


    ....not the treemenu.w program itself.

    Dez

  • FYI I tried removing the delete object frm from runner.p but I still get the same InvalidOperationException message.


    Dez

  • If you start modal form (like ShowDialog() from System.Windows.Forms.Form class) you can try following code:

    1. Insert into aForm class following public method:

    METHOD PUBLIC VOID ShowModalDialog( ):

         WAIT-FOR THIS-OBJECT:ShowDialog().

    END METHOD.

    2. Use next code to launch modal aForm from your .w code:

    DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

    frm = NEW Cls.aForm().

    frm:ShowModalDialog().

    Bye!

  • You star!

  • Ivica.Loncar schrieb:

    If you start modal form (like ShowDialog() from System.Windows.Forms.Form class) you can try following code:

    1. Insert into aForm class following public method:

    METHOD PUBLIC VOID ShowModalDialog( ):

         WAIT-FOR THIS-OBJECT:ShowDialog().

    END METHOD.

    2. Use next code to launch modal aForm from your .w code:

    DEFINE VARIABLE frm AS Cls.aForm NO-UNDO.

    frm = NEW Cls.aForm().

    frm:ShowModalDialog().

    Bye!

    I'd rather not implement the ShowModalDialog method.

    I'd prefer to be using the WAIT-FOR frm:ShowDialog () method directly in the .w file. A big benefit will be that you get access to the DialogResult:

    /* in your .w file */

    DEFINE VARIABLE oDialogResult AS System.Windows.Forms.DialogResult NO-UNDO.

    WAIT-FOR frm:ShowDialog () SET oDialogResult.

    IF Progress.Util.EnumHelper:AreEqual (oDialogResult, System.Windows.Forms.DialogResult:Ok) THEN

        ....

    There's no real benefit in creating a public method that just calls another public method (and hides the result).

  • Hi Mike,


    In terms of what I want to achieve what is advantage of having access to DialogResult (never heard of it sorry!)?


    Thanks, Dez

  • Thank you Mike, your example works ok.

    Do you have any idea how to start modeless forms (using Show() method) from .w file.

    When i try that, WAIT-FOR frm:Show() method throws exception with progress error number 13967.

  • You need to use the .NET WAIT-FOR forehand. Basically you have to replace the WAIT-FOR CLOSE OF THIS-PROCEDURE from your main window (.w) with the

    WAIT-FOR System.Windows.Forms.Application:Run () .

    You need to create a dummy object first and use the System.Windows.Forms.Application:Exit() to terminate that WAIT-FOR. See my Bravepoint VI presentation, slide 12 for sample code.

    http://www.consultingwerk.de/fileadmin/user_upload/pdf/OpenEdge%20GUI%20for%20.NET%20Adoption%20%26%20Migration%20Strategies.pdf

  • Hi Mike,

    What's the dummy object for? My application seems to work fine with just the Application:Run().

  • What's the dummy object for? My application seems to work

    fine with just the Application:Run().

    That WAIT-FOR requires at least one .NET object before it's run. So I guess in your case, you'll have touched the .NET framework before using a different object.

    Then you may ignore that.