I am using a class library to simulate and process data and return results via triggered events.
DataProcessor _dataProcessor
In it I am using a DispatcherTimer to simulate data and raise events when simulated data is available and ready to be pushed to GUI.
Was wondering how best to kill the _dataProcessor?
My experience is that setting
_dataProcessor = null;
does not kill the DispatcherTimer. The events are still raised and still passed up to the GUI.
Do I have to stop/null out the DispatcherTimer before the GAC will dispose of the class library?
Thank you for any guidance as I’m not sure the best way to approach this task in general, yet alone terminating the instance of the class library on demand.
A DispatcherTimer keeps itself alive while it is enabled, even if you don’t keep a reference to it. Rather important, nobody expects a timer to stop raising events unless asking it explicitly to Stop(). It does so by adding a reference to itself into a private List<> kept by the Dispatcher. And removing that reference in Stop().
Which in turn ensures that your DataProcessor will not get garbage collected if it has a non-static Tick event handler. Setting the reference you keep to null has no effect, the references kept by Dispatcher and the event delegate keep the object alive.
You’ll need to add a method to DataProcessor that stops the timer.