Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I dispose of NI controls at form closing

Running MS 8.0.1 + VS2005 + WXP latest updates. My app has a number of NI contols: numeric edit (linked to slider) + unlinked numeric edits + DAQ + switches. When I close the form which causes a Form_closing event to fire I try to perform cleanup actions then dispose of NI controls directly. I'm doing this because I get errors otherwise. I've also had to add try...catch blocks in odd places. This was not how I wanted to write the code, but how I'm having to. I get two kinds of behavior.
 
I have single stepped thru the code to understand what is going on. At times I have enabled debugging thru the Form1.Designer.vb code as well. I have been examining the sender object of events to see if I can trap things in code. So far I have been unsuccessful. It appears that the behavior of NI controls is sufficiently different from 'standard' controls that the default GC is insufficient.
 
First kind of behavior is a false AfterChangeValue event on the numeric edit control that is linked to the slider. The other numeric edit controls do not generate false events. This occurs when I explicitly use <numeric edit label>.dipose. When I drilled down into the sender object from the event, I see the Name of the numeric edit control. In addition I see that IsDisposing = False and Disposed = false. Therefore there is no way to catch that this is caused by my call to dipsose. Instead I do a phony Try...Catch. That fixes the problem, but it's not a good way.
 
Second kind of behavior is when the code jumps into the middel of a Switch_stateChanged event handler AFTER the switch has been disposed. This generates an runtime error that I don't know how to catch. Note: the procedure I follow in my form_closing is to check if an acq is being done. Then if it is going, I change the switch. This causes the stateChanged event to fire. This gracefully terminates the application (just like I do manually). The StateChanged event is processed correctly and runs to completion. Then the form_closing runs to completion, then the dispose mehod in DAQTask.User.vb runs to completion, then the code jumps right into the middle of the Switch_StateChanged event handler. At that point in time the sender object has been disposed and when the event handler tries to access it there is a runtime error.
 
I have looked thru documentation and found no recommended procedures for cleanup. I have given up trying to fix it in code. I will continue to let the app crash at the end until I hear a recommendation/solution to my problem. As near as I can tell, the default GC behavior is not adequate for NI applications.
0 Kudos
Message 1 of 2
(2,839 Views)
Hi Steve,

If I understand you correctly, you are saying that our Measurement Studio controls aren't being collected and disposed of properly.

If you can put together a simple example that demonstrates this behavior and post it to the forum, we would be very interested in replicating this behavior on our end.

Thanks Steve, let me know if you'll be able to accomodate this.

Dan Weiland
0 Kudos
Message 2 of 2
(2,821 Views)