Subscribe Bookmark RSS Feed

C# closes JMP after running

vince_faller

Super User

Joined:

Mar 17, 2015

I'm trying to launch an addin (plus a few other things) with a simple C# program.  

 

It works great, the problem being.  If JMP isn't already open, as soon as it's done running, JMP Exits.  I don't really want to keep the console open if I don't have to.  Is there a command that will just leave it open after execution?

1 ACCEPTED SOLUTION

Accepted Solutions
Justin_Chilton

Joined:

Aug 27, 2015

Solution

I did some more testing and it looks like the behavior is different if you are using a Windows Forms application vs a console application. I am assuming you are using a console application based on your OP. My previous post was based on using a Windows Forms application.

If you have a console application, doing something like myJMP.ShowStartupWindow() should prevent JMP from closing when the program finishes executing. 

This method will open JMP and keep it open after the program finishes executing.

static void Main(string[] args)
{

    JMP.Application myJMP;
    myJMP = new JMP.Application();
    myJMP.Visible = true;
    myJMP.ShowStartupWindow();
            
}

However, there is one problem with this method. You will need to kill the jmp.exe in Task Manager because the Exit JMP menu item is disabled. (Actually, the previous code I provided also has this problem.) 

 Capture.PNG

EDIT 09MAR17 (For people of the future):

I have realized that my original comment (above or below, depending on where you are reading this) was correct and the information in this post above this edit does not work all the time. Below is a workaround that I came up with that creates a dummy table and closes it to get JMP to stay open. I have also added @briancorcoran's suggestion for using myJMP.EnableInteractiveMode(true) to enable the 'Exit JMP' menu item.

static void Main(string[] args)
{

    JMP.Application myJMP;
    myJMP = new JMP.Application();
    myJMP.Visible = true;
    myJMP.ShowStartupWindow();
    myJMP.EnableInteractiveMode(true);

    // Needed to keep JMP from automatically closing
    JMP.DataTable dt = myJMP.NewDataTable("test");
    myJMP.RunCommand(@"Close(Data Table(""test""), NoSave)");

}

 

@vince_faller, FYI

 

Justin
5 REPLIES
Craige_Hales

Staff

Joined:

Mar 21, 2013

Just tried the C# automation example in JMP 13; it left JMP running after I closed the example and the IDE.

Open C# app, then press button to automate JMPOpen C# app, then press button to automate JMPClose the C# app, JMP stays openClose the C# app, JMP stays open

I guess this is an existence proof that you can do what you are asking, but I'm not sure what makes it work. I did run across a comment about releasing interfaces http://stackoverflow.com/questions/18154315/excel-process-not-closing for someone that wanted the opposite behavior.

 

Craige
Justin_Chilton

Joined:

Aug 27, 2015

JMP will close if you don't have a reference to anything besides the JMP.Application. 

In the example below, JMP will stay open because I have a reference to a JMP data table.  

JMP.Application myJMP;
JMP.DataTable dt;

myJMP = new JMP.Application();
myJMP.Activate();
myJMP.Visible = true;

myJMP.ShowStartupWindow();
myJMP.RunCommand(@"Open(""$SAMPLE_DATA\Big Class.jmp"")");
dt = myJMP.GetTableHandleFromIndex(1);

 

Justin
vince_faller

Super User

Joined:

Mar 17, 2015

Good to know.  Can I just give it a dummy var?

Justin_Chilton

Joined:

Aug 27, 2015

Solution

I did some more testing and it looks like the behavior is different if you are using a Windows Forms application vs a console application. I am assuming you are using a console application based on your OP. My previous post was based on using a Windows Forms application.

If you have a console application, doing something like myJMP.ShowStartupWindow() should prevent JMP from closing when the program finishes executing. 

This method will open JMP and keep it open after the program finishes executing.

static void Main(string[] args)
{

    JMP.Application myJMP;
    myJMP = new JMP.Application();
    myJMP.Visible = true;
    myJMP.ShowStartupWindow();
            
}

However, there is one problem with this method. You will need to kill the jmp.exe in Task Manager because the Exit JMP menu item is disabled. (Actually, the previous code I provided also has this problem.) 

 Capture.PNG

EDIT 09MAR17 (For people of the future):

I have realized that my original comment (above or below, depending on where you are reading this) was correct and the information in this post above this edit does not work all the time. Below is a workaround that I came up with that creates a dummy table and closes it to get JMP to stay open. I have also added @briancorcoran's suggestion for using myJMP.EnableInteractiveMode(true) to enable the 'Exit JMP' menu item.

static void Main(string[] args)
{

    JMP.Application myJMP;
    myJMP = new JMP.Application();
    myJMP.Visible = true;
    myJMP.ShowStartupWindow();
    myJMP.EnableInteractiveMode(true);

    // Needed to keep JMP from automatically closing
    JMP.DataTable dt = myJMP.NewDataTable("test");
    myJMP.RunCommand(@"Close(Data Table(""test""), NoSave)");

}

 

@vince_faller, FYI

 

Justin
briancorcoran

Joined:

Jun 23, 2011

If you use the "EnableInteractiveMode(True)" on the application object, this will enable the Exit menu item and you will not need to kill the process through the Task Manager.

 

Brian Corcoran

JMP Development