Highlighted
Super Contributor.
Super Contributor.
1303 views

Using Application.Run(ApplicationContext) in Visual COBOL

Jump to solution

We have a hybrid application that runs both native and managed functions from a native menu.  The first program run is managed.  I want to start a message loop in this program then show each managed form with the Form::Show() method.  When I execute Application..Run(ApplicationContext) in the debugger the output window displays "Step into: Stepping over non-user code 'System.Windows.Forms.Application.ThreadContext.ThreadContext'" and it just hangs.

This is my code:

 class-id. Mgload as "Mgload.Mgload".
       method-id Startup static attribute STAThread()
       local-storage section.
           01 context type MgLoad.MyApplicationContext.
       procedure division.
           set context to new type MgLoad.MyApplicationContext
           invoke type Application::Run(context)
           goback.
       end method.

       end class.

  $set ilusing"System.Windows.Forms"
       class-id MgLoad.MyApplicationContext
                inherits from type System.Windows.Forms.ApplicationContext.

       working-storage section.

       method-id MyApplicationContext private.
       local-storage section.
       procedure division.
           invoke type MessageBox::Show("Arrived !")
           *> start up my native menu
           goback.
       end method.

       end class.

I am also uploading the project for this.

Phil Levin

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Super Contributor.
Super Contributor.

RE: Using Application.Run(ApplicationContext) in Visual COBOL

Jump to solution

Changing the constructor name to "New"  works like you said but unfortunately it's not returned to after I start up the native menu, so the message loop never gets started;  "invoke type Application::Run(context)"

never gets performed.  In the C# example, the MyApplicationContext class showed two forms using the Show method which is different from calling a native menu.  I really don't see a way we can start a message loop on the managed thread.  Our earlier approach was to run each managed function on its own thread and to show the main form of each using "Run(MainForm)", which started a message loop.  We should probably stick with that.

Phil Levin

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Using Application.Run(ApplicationContext) in Visual COBOL

Jump to solution

I think that you probably converted this from a C# example that used the method name of MyApplicationContext as the constructor.to invoke when a new instance of the MyApplicationContext class was created.

This works in C# because the default constructor method name is the same as the class name.

In COBOL the default constructor name is "New".

If you change the name of your constructor method from MyApplicationContext to New then it will run as expected.

method-id New private.
procedure division.

      invoke type MessageBox::Show("Arrived !")
     *> start up my native menu
      goback.
end method

Thanks.

0 Likes
Highlighted
Super Contributor.
Super Contributor.

RE: Using Application.Run(ApplicationContext) in Visual COBOL

Jump to solution

Changing the constructor name to "New"  works like you said but unfortunately it's not returned to after I start up the native menu, so the message loop never gets started;  "invoke type Application::Run(context)"

never gets performed.  In the C# example, the MyApplicationContext class showed two forms using the Show method which is different from calling a native menu.  I really don't see a way we can start a message loop on the managed thread.  Our earlier approach was to run each managed function on its own thread and to show the main form of each using "Run(MainForm)", which started a message loop.  We should probably stick with that.

Phil Levin

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.