05-25-2016 07:20 AM - edited 05-25-2016 07:21 AM
I try to restart TestStand engine between 2 sequence file executions. Using the TS API from VB .Net.
Steps: Start the TestStand engine -> execute a sequence -> close the engine -> start the engine again -> execute a sequence ....
When I want to start the second execution I get the following error:
"
Exception thrown: 'System.Runtime.InteropServices.COMException' in RestartEngineTest.exe
Additional information: Operation failed because TestStand Engine was shutdown.
"
What would be the correct engine restart procedure?
2'nd problem: If I try to force the Garbage Collector
'GC.Collect()
'GC.WaitForPendingFinalizers()
'GC.Collect()
'GC.WaitForPendingFinalizers()
after Engine.Shutdown(True) complete application hangs "inside" the first GC.Collect().
A sample solution is Enclosed.
I start the execution with "myTsEngine.NewExecution"
Upon API.UIMessageCodes.UIMsg_EndExecution I release the sequence file and the model.
Upon API.UIMessageCodes.UIMsg_ShutDownComplete I unload all modules and type palletes and call Shutdown(false) followed on second entry by Shutdown(True)
Private Sub StartSequenceExecution(nameOfExistingSequenceFile As String)
Try
myTsEngine = New API.Engine()
myTsEngine.LoadTypePaletteFilesEx()
sequenceFile = myTsEngine.GetSequenceFileEx(nameOfExistingSequenceFile, 107)
modelSequenceFile = myTsEngine.GetSequenceFileEx("SequentialModel.seq", 107)
myExecution = myTsEngine.NewExecution(sequenceFile, "Single Pass", modelSequenceFile, False, 0)
Catch ex As Exception
Throw New Exception("TestStand Api Problem!" & vbCrLf & ex.Message)
End Try
End Sub
Public Sub TS_UI_Message_Handler(ByVal aktUImessage As NationalInstruments.TestStand.Interop.API.UIMessage) Handles myTsEngine.UIMessageEvent
Try
Select Case aktUImessage.Event
Case Is = API.UIMessageCodes.UIMsg_EndExecution
Try
If Not sequenceFile Is Nothing Then
If sequenceFile.CanUnload Then
myTsEngine.ReleaseSequenceFileEx(sequenceFile, 5) ' UnloadFile, UnloadFileIfModified
sequenceFile = Nothing
End If
End If
If Not modelSequenceFile Is Nothing Then
If modelSequenceFile.CanUnload Then
myTsEngine.ReleaseSequenceFileEx(modelSequenceFile, 5) ' UnloadFile, UnloadFileIfModified
modelSequenceFile = Nothing
End If
End If
myTsEngine.ShutDown(False)
Catch ex As Exception
' ignore
End Try
Case Is = API.UIMessageCodes.UIMsg_ShutDownComplete
If Not isFinalShutdown Then
myExecution = Nothing
myTsEngine.UnloadAllModules()
myTsEngine.UnloadTypePaletteFiles()
'GC.Collect()
'GC.WaitForPendingFinalizers()
'GC.Collect()
'GC.WaitForPendingFinalizers()
myTsEngine.ShutDown(True) ' 2'nd shutdown
isFinalShutdown = True
Else
myTsEngine = Nothing
'GC.Collect()
'GC.WaitForPendingFinalizers()
'GC.Collect()
'GC.WaitForPendingFinalizers()
MsgBox("First Execution Complete, Starting the second one...", MsgBoxStyle.ApplicationModal Or MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
StartSequenceExecution("Test.seq")
End If
Case Else
' Optional: Do something or not to notify the the user/programmer about unknown messages !
End Select
aktUImessage.Acknowledge()
aktUImessage = Nothing
Catch ex As Exception
MsgBox("UIMessageEvent Error: " & ex.Message, MsgBoxStyle.ApplicationModal Or MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
Finally
End Try
End Sub
05-26-2016 04:46 PM
Hi CristianL.,
Just in case, have you seen this Knowledge Base article?
Starting and Shutting Down TestStand from a .NET User Interface
http://zone.ni.com/reference/en-XX/help/370052P-01/tsfundamentals/infotopics/net_ui_start_shutdown/
05-27-2016 02:25 AM
Yes 🙂
10-29-2021 05:23 AM
Hello,
I had a similar problem and this case did help me to solve it.
That's the reason I want to Link my solved case here: 😉
Best Rgds
MAGL21