10-27-2020 05:24 PM
I am making an automated sequence generation script in C#. My code successfully creates the sequence file, but when the program is closing out it results in an error popup that it has stopped working. I believe that the TestStand engine I generated to create the sequence file was not closed out correctly.
I have been trying to follow the steps from the support article Shutting Down the Engine, but the popup still persists. Are there any other steps I should be taking that aren't listed in this guide? I am trying to not have a TestStand interface pop up at all, just have it execute in the background. Thanks.
10-28-2020 08:54 AM
There's actually a different version of this document specific to .NET: https://zone.ni.com/reference/en-XX/help/370052AA-01/tsfundamentals/infotopics/net_ui_start_shutdown...
It's hard to say without more details on your error, but it sounds like you're running into this:
TestStand reports object leaks—The .NET CLR uses a form of automatic memory management, which includes garbage collection to reclaim memory, that is no longer in use. When the last reference to a TestStand COM object is released, .NET places the object reference into garbage collection, and the object is finalized at a later time.
If the TestStand engine performs a shutdown before garbage collection finalizes TestStand objects, and you have the TestStand debug option Report Object Leaks enabled, TestStand reports non-finalized objects as leaks, even though the application no longer holds a reference to the objects.
Hope this helps!
Trent
10-28-2020 01:12 PM - edited 10-28-2020 01:15 PM
I did stumble upon that page, as well. I tried using the exact methodology described in it, but when I do it never creates my new sequence file. Here is my code, where I use a slightly modified version of the SequenceFileXMLParserClass given in the TestStand examples for my entry point method.
[STAThread]
void LaunchTSApplication()
{
// Create application domain, call MainEntryPoint, and
// cleanup before return.
LaunchTestStandApplicationInNewDomain.LaunchProtected(
new LaunchTestStandApplicationInNewDomain.
MainEntryPointDelegateWithArgs(MainEntryPoint),
null,"Sequence Generator",new LaunchTestStandApplicationInNewDomain.
DisplayErrorMessageDelegate(DisplayErrorMessage));
}
// Main entry point executed in new application domain.
private void MainEntryPoint(string[] args)
{
// Obtain a reference to existing Engine.
Program._engine = new Engine();
Program._engine.LoadTypePaletteFilesEx(
TypeConflictHandlerTypes.ConflictHandler_Prompt, 0);
// Launch your application here.
// e.g., Application.Run(new MainForm());
using (SequenceFileXMLParserClass XMLParser =
new SequenceFileXMLParserClass(_engine, out bool cancel, "SeqFile.xml"))
{
SequenceFileXMLParserClass.SequenceFileData sfd =
XMLParser.deserializeXMLFile();
XMLParser.buildSequenceFileFromXMLData(sfd);
XMLParser.saveSequenceFile("NewSeqFile");
}
// Engine clean up.
Program._engine = null;
}
// Called if exception occurs in MainEntryPoint.
private static void DisplayErrorMessage(string caption, string message)
{
// Handle error here.
// e.g., MessageBox.Show(message, caption);
}
I know that newly created Sequence object should be detached from the _engine when the SequenceFileXMLParserClass is destroyed. Are there any other objects attached to the _engine object that would stop it from shutting down correctly?