NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Cleaning up after programmatically calling NewExecution

Hi folks,

 

I'm attempting to add NI TestStand support to an existing test executive.  This will allow a project team to run TestStand sequences without needing to learn a new GUI interface.  The existing test executive is implemented in .Net so I'm using that version of the API to implement TestStand support.  I thought everything was working fine, but I've discovered that after every run of my example tests some additional threads are created and not cleaned up.  Basically it appears TestStand is leaking a thread or two after every call to NewExecution.  This is leading me to believe I'm missing a step in cleaning up existing Executions.  Here is a snippet of my code:

 

public void SetUp()

{

//Register the UIMessageCallback

_engine.UIMessageEvent += this.MessageCallback;

}

public void Test()

{

this._doneExecuting = false;

try

{

_exe = _engine.NewExecution(
this._seqFile, this._name, null, false, ExecutionTypeMask.ExecTypeMask_Normal, null, null, null);

}

catch (Exception)

{

GenerateTestPoint(
"Sequence", _name, "Error"); return;

}

while (!this._doneExecuting)

{

System.Threading.Thread.Sleep(0);} 

}

 

How can I correctly clean up after I detect the test is finished?

 

Regards,

Jason

0 Kudos
Message 1 of 2
(2,577 Views)

A collegue suggested adding the following code to dispose of the execution.  My initial testing seems to suggest it's working:

 

         public void TearDown()
        {
            //Unregister the UIMessageCallback
            _engine.UIMessageEvent -= this.MessageCallback;

            // Free up Execution
            if (this._exe != null)
            {
                this.NAR(this._exe);
                this._exe = null;
            }
        }

 

 ...

 

        private void NAR(object o)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
            }
            catch { }
            finally
            {
                o = null;
            }
        }

0 Kudos
Message 2 of 2
(2,566 Views)