pierre Posted September 8, 2011 Report Share Posted September 8, 2011 (edited) Hello, I am actualy designing a program using a Model-View-Presenter Template. Views and presenters are contretized by dynamic lauched Vis. Models are shared between Presenters using LV References. Main models are instantiated by the main presenter. Others models, that might belong to main models can be instantiated by sub presenter within sub presenter thread. Using execution-trace I noticed that all references created in sub presenter thread are destroyed when thread stops. That is very annoying because the aim of sub presenters is to modifiy and eventualy create sub models. And if sub models can not be reused after sub presenter is destroyed, my design pattern will never work. Does anybody ever met this situation? Is there any way to ask labview runtime to keep valid references created in dynamic launched VI when this one stops? thanx for answer. Pierre Edited September 8, 2011 by pierre Quote Link to comment
Mark Smith Posted September 8, 2011 Report Share Posted September 8, 2011 There are a couple of things that come to mind. One is to transfer ownership of the ref from the VI that launches a dynamic VI in a new thread to the dynamic VI. Then it doesn't matter if the caller goes out of scope. This happens with the arguments to the Run method from the invoke node (LV 2010 and earlier) - LV 2011 has the new Async VI call primitive and it can do the same thing by setting the arguments to the VI Ref open method. There's a recent thread here on LAVA that has much info about that (http://lavag.org/top...nchronous-call/). The other method that might work is to create a functional global that is a "reference pool". Call this FGV by something (like the main panel) that never gets unloaded and store create all of your refs in there. The FGV should never go out of scope and the refs should not be destroyed. In this case, do not transfer ownership of the ref to the called VI. This might work for you. Mark Quote Link to comment
Yair Posted September 8, 2011 Report Share Posted September 8, 2011 (edited) Cross-post: http://forums.ni.com/t5/LabVIEW/Reference-loss-when-created-by-Dynamic-VI/m-p/1698122#M601558 It's considered polite to provide a link to the other thread if you cross-post. Edited September 8, 2011 by Yair Quote Link to comment
pierre Posted September 8, 2011 Author Report Share Posted September 8, 2011 There are a couple of things that come to mind. One is to transfer ownership of the ref from the VI that launches a dynamic VI in a new thread to the dynamic VI. Then it doesn't matter if the caller goes out of scope. This happens with the arguments to the Run method from the invoke node (LV 2010 and earlier) - LV 2011 has the new Async VI call primitive and it can do the same thing by setting the arguments to the VI Ref open method. There's a recent thread here on LAVA that has much info about that (http://lavag.org/top...nchronous-call/). The other method that might work is to create a functional global that is a "reference pool". Call this FGV by something (like the main panel) that never gets unloaded and store create all of your refs in there. The FGV should never go out of scope and the refs should not be destroyed. In this case, do not transfer ownership of the ref to the called VI. This might work for you. Mark I first tried Global Functionnal with no success. Actualy, even if creation is made in global fonctionnal, global fonctionnal is called in Dynamic Vi context, so Reference seems to belong to Dynamic Vi context... The solution I have choosen is post on NI forum : http://forums.ni.com...1698122#M601558 Thanx for answers Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.