Hello there!
Im trying to execute a sequence using TestStand API and then close all references, but the End Execution event does not seem to be thrown.
I had the same issue as the thread called " Programati
My code is the following
_axAppMgr.EndExecution += new NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_EndExecutionEventHandler(_axAppMgr_EndExecution);
_axAppMgr.ExecutionClosed += new NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_ExecutionClosedEventHandler(_axAppMgr_ExecutionClosed);
void _axAppMgr_QueryCloseExecution(object sender, _ApplicationMgrEvents_QueryCloseExecutionEvent e)
{
e.opt = QueryCloseExecutionOptions.QueryCloseExecution_AutoCloseWhenDone;
}
void _axAppMgr_EndExecution(object sender, _ApplicationMgrEvents_EndExecutionEvent e)
{
ExecutionRunStates runState;
ExecutionTerminationStates termState;
e.exec.GetStates(out runState, out termState);
if (termState != ExecutionTerminationStates.ExecTermState_Normal)
Trace.WriteLine(DateTime.Now + " -----EXECUTION " + e.exec.DisplayName + "Aborted ---------");
else
Trace.WriteLine(DateTime.Now + " -----EXECUTION " + e.exec.DisplayName + " Terminated ---------");
ExecutionEnd = true;
}
public bool Run(string UUTName, string sequencePath )
{
bool output = false;
int TimeOut = -1;
string name = "";
ExecutionRunStates runState;
ExecutionTerminationStates TerminationState;
try
{
name = DateTime.Now.ToString("yyyy-MM-dd") + " Test " + UUTName;
if (!_axAppMgr.IsStarted)
_axAppMgr.Start();
seqFile = _axAppMgr.GetEngine().GetSequenceFileEx(sequencePath);
Main = seqFile.GetSequenceByName("MainSequence");
Main.OptimizeNonReentrantCalls = true;
Main.Type = SequenceTypes.SeqType_ExeEntryPoint;
execution = _axAppMgr.GetEngine().NewExecution(seqFile, "MainSequence",null, false, ExecutionTypeMask.ExecTypeMask_CloseWindowWhenDone);
execution.TracingDisabled = true;
execution.RTEOptionForThisExecution = RTEOptions.RTEOption_Ignore;
execution.ClearTemporaryBreakpoints();
execution.DisableResults = true;
bool isExecuting = seqFile.IsExecuting;
bool wait = execution.WaitForEndEx(TimeOut, true, null, null);
execution.GetStates(out runState,out TerminationState );
execution.Terminate();
_axAppMgr.SetAutoCloseExecution(execution, true);
_axAppMgr.CloseExecution(execution);
execution.GetStates(out runState, out TerminationState);
while (!ExecutionEnd)
System.Threading.Thread.Sleep(1000);
Terminate();
execution.GetStates(out runState, out TerminationState);
}
catch (COMException ex)
{
Trace.WriteLine(ex.StackTrace + " " + ex.Message);
}
finally
{
TSHelper.DoSynchronousGCForCOMObjectDestruction();
Quit();
}
return output;
The problem is, when I deactivate the
e.opt = QueryCloseExecutionOptions.QueryCloseExecution_AutoCloseWhenDone;
command the execution fails to close.
If I set the option to
e.opt = QueryCloseExecutionOptions.QueryCloseExecution_ShowDialog;
and manually select auto close , then the Execution Close event is thrown.
Could anyone help me finding out what's wrong with my code?
Thank you in advance for your time