Choose Language Hide Translation Bar
Highlighted
GregG
Level I

C# Automation: JMP window doesn't open with JMP process in background

Hi all,

I'm having a trouble with openening the JMP window when JMP process is running as background process.

Once this process is killed, everything works fine.

Is there way make automation work without manually killing this process?

 

Thanks,

Greg

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ChrisM
Level III

Re: C# Automation: JMP window doesn't open with JMP process in background

I've worked quite a bit with JMP / C# automation. Automation should attach to open processes of JMP, sometime this attachment fails (very rare), then my code will alert the user and automatically close other JMP processes and try again.

private bool CheckJMPPresent()
{
bool jmpExists = Registry.ClassesRoot.OpenSubKey("TypeLib\\{DCD36DE0-78F8-11CF-9E68-0020AF24E9FE}\\1.0\\0\\win32", false) != null;
if (!jmpExists) return false; //no registry key, then JMP doesn't exist

try
{
JMP.Application myJMP;
myJMP = new JMP.Application();
myJMP.Visible = true;

jmpExists = true;
}
catch (Exception)
{


jmpExists = false;
}

if (jmpExists) return true;


//if having trouble attaching to JMP, then start fresh, kill all JMP processes and try again!
foreach (var process in Process.GetProcessesByName("jmp"))
{

DialogResult d = MessageBox.Show("All JMP windows will be closed, please save files prior to clicking YES!!! Click NO, to disable JMP functionality, and leave JMP open", "JMP Warning", MessageBoxButtons.YesNo);
if (d != DialogResult.Yes)
{
//this.Shown += new EventHandler(MyForm_CloseOnStart);
return false;
}



process.Kill();//killing JMP in case JMP has crashed
}
System.Threading.Thread.Sleep(200);//need to wait at least 10 ms after killing JMP prior to creating instance (not sure why?) Automation may be trying to attach to a closing process.

try
{
JMP.Application myJMP;
myJMP = new JMP.Application();
myJMP.Visible = true;
jmpExists = true;
}
catch (Exception)
{


jmpExists = false;
}


return jmpExists;

View solution in original post

2 REPLIES 2
Highlighted
ChrisM
Level III

Re: C# Automation: JMP window doesn't open with JMP process in background

I've worked quite a bit with JMP / C# automation. Automation should attach to open processes of JMP, sometime this attachment fails (very rare), then my code will alert the user and automatically close other JMP processes and try again.

private bool CheckJMPPresent()
{
bool jmpExists = Registry.ClassesRoot.OpenSubKey("TypeLib\\{DCD36DE0-78F8-11CF-9E68-0020AF24E9FE}\\1.0\\0\\win32", false) != null;
if (!jmpExists) return false; //no registry key, then JMP doesn't exist

try
{
JMP.Application myJMP;
myJMP = new JMP.Application();
myJMP.Visible = true;

jmpExists = true;
}
catch (Exception)
{


jmpExists = false;
}

if (jmpExists) return true;


//if having trouble attaching to JMP, then start fresh, kill all JMP processes and try again!
foreach (var process in Process.GetProcessesByName("jmp"))
{

DialogResult d = MessageBox.Show("All JMP windows will be closed, please save files prior to clicking YES!!! Click NO, to disable JMP functionality, and leave JMP open", "JMP Warning", MessageBoxButtons.YesNo);
if (d != DialogResult.Yes)
{
//this.Shown += new EventHandler(MyForm_CloseOnStart);
return false;
}



process.Kill();//killing JMP in case JMP has crashed
}
System.Threading.Thread.Sleep(200);//need to wait at least 10 ms after killing JMP prior to creating instance (not sure why?) Automation may be trying to attach to a closing process.

try
{
JMP.Application myJMP;
myJMP = new JMP.Application();
myJMP.Visible = true;
jmpExists = true;
}
catch (Exception)
{


jmpExists = false;
}


return jmpExists;

View solution in original post

Highlighted
GregG
Level I

Re: C# Automation: JMP window doesn't open with JMP process in background

Thank you @ChrisM!

It's very close to what I needed.

Our users may want to keep JMP in foreground open. So I just need to find background processes.

With replacing foreach loop:

//if having trouble attaching to JMP, then start fresh, kill all JMP processes and try again!
foreach (var process in Process.GetProcessesByName("jmp"))
{

DialogResult d = MessageBox.Show("All JMP windows will be closed, please save files prior to clicking YES!!! Click NO, to disable JMP functionality, and leave JMP open", "JMP Warning", MessageBoxButtons.YesNo);
if (d != DialogResult.Yes)
{
//this.Shown += new EventHandler(MyForm_CloseOnStart);
return false;
}
to:
 
//Kill all the JMP processes in background
foreach (var process in Process.GetProcessesByName("jmp"))
{
if (process .MainWindowHandle == IntPtr.Zero)
    {
        process .Kill();
    }
}
System.Threading.Thread.Sleep(200);
it works like charm. :)
 
 
 
Article Labels

    There are no labels assigned to this post.