PDA

View Full Version : How to cleanly shut down indicator


richard
06-07-2006, 03:44 AM
Hi. In my indicator, I have initialized the following event handler (in OnBarUpdate()):

MarketData.MarketDataItem += new MarketDataItemEventHandler(MarketData_MarketDataIt em);

I've noticed that even when I remove the indicator from my chart, this event is still kicking off. My indicator also opens up 3 Windows forms and my question is: how can I ensure that when the indicator is removed from the chart, the above event gets unhooked and I can close out my 2 Windows forms.

I tried the following deconstructor code:

// my destructor code

~ZooPulse()

{

Print("destruct1a!");

Print("destruct3!");

zform.Close();

zform = null;

Print("destruct2!");

MarketData.MarketDataItem -= new MarketDataItemEventHandler(MarketData_MarketDataIt em);

Print("destruct4!");

//System.GC.Collect();

Print("DONE");

}



where zform is my Windows form. I get the first 2 Print statements, then nothing else. So I know it doesn't like my zform.Close(). I've tried commenting out the form cleanup and just removing the MarketData event handler, but that also doesn't print "destruct4", so I know it failed on that too.



How do I remove my event handler and close out my forms when the user Removes the indicator on the chart? Thanks.

NinjaTrader_Ray
06-07-2006, 08:09 AM
Unfortunately there is no guaranteed way to unhook the event handler. You for sure are getting into advanced logic that is really not an officially supported feature. We have added a TearDown() logic for NT6 which will be in beta in August which will allow you to disconnect any handlers. You could try Dispose() method but there is no guarantee that this method is called immediately upon removing the indicator from a chart.

Ray