07-13-2007 02:09 PM
I have a TestStand sequence that calls a generic .Net step. At some point in its execution, this .Net step needs to make a decision. Instead of simply hardcoding a behavior, our solution is to have the .Net component start a new TestStand sequence execution to
perform the decision making:
[…]
NationalInstruments.TestStand.Interop.API.Execution ex =
seqCtx.Engine.NewExecution(
seqCtx.SequenceFile,
"decisionMakingSequence",
null,
false,
0x1 | 0x2 | 0x10,
parameterObj,
null,
null);
ex.WaitForEnd(-1, true, null);
switch(parameterObj.GetValString("status”, 0))
{
[…]
}
This allows a user of our .Net component override / enhances some behaviors.
However for a reason that I cannot explain, when the execution of the TestStand sequence terminates the .Net AppDomain that the execution was initially being used gets unloaded. Is it possible that, when creating a new execution (seqCtx.Engine.NewExecution(…)) TestStand creates a new .Net AppDomain and then use it as default, unloading the previous one which is no longer required? This causes us some problems as static content gets garbage collected.
Thank,
Marc-Andre Parent,
Proligent development team.
07-16-2007 05:49 PM
Hey Marc-Andre,
I created a .NET assembly in which I inserted the following function:
public void Test(SequenceContext a)When I ran this, the ID was the same value before and after. Have you tried checking the ID value?
07-17-2007 09:46 AM
public
class TestClass{
static TestClass() //Static constructor
{
AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);
static
void CurrentDomain_DomainUnload(object sender, EventArgs e){
MessageBox.Show("CurrentDomain_DomainUnload :" + (sender as AppDomain).Id.ToString());
}
public void Test(SequenceContext a){...}
...
After I close the sequence execution window, I get a "CurrentDomain_DomainUnload : 2" popup. Unfortunately, I have so far failed to write a short code sample that reproduce my bug (I can only repro it with my full app. which is not easily portable). I have also noticed that the bug repro depends a lot on the TestSand environment. ex: If I open the StationCallback.seq file, the bug's gone! Could the problem be in TestStand itself, it the way it handles .Net AppDomains? Has anybody ever heard of such an issue?
-Thanks for helping!
07-18-2007 03:18 PM
07-19-2007 01:12 PM
07-20-2007 10:48 AM
I just tried this: (not too sure if this is the fix that was suggested)
Have a static variable:
private static NationalInstruments.TestStand.Interop.API.Execution m_execution;
and use it to store every new execution:
m_execution = seqCtx.Engine.NewExecution(...);
This seems to work around my issue (but I really ain't too sure why!)
07-20-2007 02:37 PM
07-20-2007 03:03 PM
Thank you for
the explanation.I will try
to think of a mechanism that avoids the memory leaks. Since I’m developing .Net plug-ins for TestStand (rather than an application that uses TestStand as its executing engine) I really don’t want to assume anything on the TestStand sequences that will use my .Net modules.