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.