SE instability

 

Hi!

Is any posibility to detect Solid Edge instability or crash? I have applications using SE and after some workflows on some computers these computers became frozen. So can I detect this to warn user and close my apps? I work with versions SE 20, SE ST and SE ST2.

Thaks for help

Pavel

 

 

Posted by: Pavel Bartolotti
Post date: 3/11/2009 10:46:15 PM

3 REPLIES

RE: SE instability

 

Hi Pavel,

 

I think the easiest way for you to implement this is to use a background thread to perform checks at set intevals (e.g. 5000ms). In the background thread you will need to start a new thread to check for a timeout and then call a method on the Solid Edge interface (be careful to call Activator.GetActiveObject again and NOT to use the Solid Edge interface from your main thread). If the method succeeds then kill the timeout thread and exit, if the timeout thread times out then you should kill the background thread and then shut down your apps.

If you want I could throw together a small example for you - just let me know.

 

Cheers

Calum

 

P.S. I don't think you'll be getting much help for ST 2 for a while...

 

Posted by: Calum McLellan
Post date: 3/11/2009 11:05:20 PM

RE: SE instability

 

Hi Calum,

thanks for quick response.

I know SE ST2 is not released yet, but we are already working with developers builds. So I was just asking

Example from you would be nice. It is always better to have some.

And is any posibility how to check where is the problem when not only SE is frozen but my app is frozen too?

Because in this case your solution is not enough.

 

Thank you

Pavel

 

Posted by: Pavel Bartolotti
Post date: 3/11/2009 11:52:46 PM

RE: SE instability

 

Hi Pavel,

 

Here's a small example. I have just used Thread objects instead of something like the BackgroundWorker class to make it easier to see what is actually going on. This may be a bit hard on resources as the timeout thread is continually newly created and then discarded - you may want to make this cade a bit less wasteful with resources. Paste this code into a new Console application.

using System;

using System.Threading;

using System.Runtime.InteropServices;

using System.Windows.Forms;

 

namespace StabilityTest

{

class Program

{

private Thread m_backgroundThread;

private Thread m_timeoutThread;

private Thread m_mainThread;

 

private Form m_mainForm;

 

static void Main(string[] args)

{

Program program = new Program();

program.Start();

}

 

private void Start()

{

 

/* Create a form on the main thread - this is used to check the response of this app */

m_mainForm = new Form();

m_mainForm.WindowState = FormWindowState.Minimized;

m_mainForm.Show();

 

/* Store the main thread - used to terminate the app */

m_mainThread = Thread.CurrentThread;

 

/* Start the background thread to check if Solid Edge

* is still available and responding */

m_backgroundThread = new Thread(BackgroundCheck);

m_backgroundThread.Start();

 

/* Simulate work with solid edge */

int count = 0;

SolidEdgeFramework.Application solidEdge = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");

try

{

while (++count

{

solidEdge.Caption = count.ToString();

Application.DoEvents();

Thread.Sleep(100);

}

/* Simulate an application hang by pausing the thread */

Console.WriteLine("Simulating Hang...");

Thread.Sleep(10000);

}

finally

{

Marshal.ReleaseComObject(solidEdge);

}

Console.ReadLine();

}

 

private void CheckResponse()

{

if (m_mainForm.InvokeRequired)

{

Console.WriteLine("Checking response from background thread");

m_mainForm.Invoke(new MethodInvoker(CheckResponse));

}

}

 

private void BackgroundCheck()

{

/* Simulate work with solid edge */

SolidEdgeFramework.Application solidEdge = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");

try

{

while (true)

{

/* Start a new thread to check if this thread hangs for more than five seconds */

m_timeoutThread = new Thread(TimeoutCheck);

m_timeoutThread.Start();

 

/* Perform interaction with SolidEdge and also check the

* response of the main thread */

solidEdge.Caption = "TimeoutCheck";

CheckResponse();

 

Console.WriteLine("Response OK");

 

/* Abort the timeout thread */

m_timeoutThread.Abort();

 

/* Wait five seconds for the next loop */

Thread.Sleep(5000);

}

 

}

catch (ThreadAbortException)

{

/* Ignore this as we have aborted the thread */

}

finally

{

Marshal.ReleaseComObject(solidEdge);

}

}

 

private void TimeoutCheck()

{

try

{

Console.WriteLine("Starting timeout check");

 

/* Sleep for five seconds - if the thread is still

* running after this then solid edge isn't responding */

Thread.Sleep(5000);

 

/* Abort the thread and stop the application */

Console.WriteLine("App Hang - Press enter key to abort");

Console.ReadLine();

 

m_backgroundThread.Abort();

m_mainThread.Abort();

}

catch (ThreadAbortException)

{

/* Ignore this as we have aborted the thread */

Console.WriteLine("Timeout check aborted");

Console.WriteLine();

}

}

}

 

}

 

 

Hope this helps

Calum

 

Posted by: Calum McLellan
Post date: 3/12/2009 1:19:02 AM