Supponiamo Ho una forma aperta tramite il metodo .ShowDialog().C# - Rimuovere i gestori di eventi - eventi FormClosing o il metodo Dispose()
Ad un certo punto mi attribuiscono alcuni gestori di eventi ad alcuni controlli sul form.
ad es.
// Attach radio button event handlers.
this.rbLevel1.Click += new EventHandler(this.RadioButton_CheckedChanged);
this.rbLevel2.Click += new EventHandler(this.RadioButton_CheckedChanged);
this.rbLevel3.Click += new EventHandler(this.RadioButton_CheckedChanged);
Quando il modulo si chiude, devo rimuovere questi gestori, giusto?
Attualmente, sto facendo questo quando l'evento FormClosing è sparato.
ad es.
private void Foo_FormClosing(object sender, FormClosingEventArgs e)
{
// Detach radio button event handlers.
this.rbLevel1.Click -= new EventHandler(this.RadioButton_CheckedChanged);
this.rbLevel2.Click -= new EventHandler(this.RadioButton_CheckedChanged);
this.rbLevel3.Click -= new EventHandler(this.RadioButton_CheckedChanged);
}
Tuttavia, ho visto alcuni esempi in cui i gestori vengono rimossi nel metodo Dispose().
Esiste un modo "migliore pratica" per farlo?
(con C#, WinForms, NET 2,0)
Grazie.
Perché dovresti prenderti cura di te stesso? Afaik il GC lo farà per te. – Fabian
@Fabian: se avessi già saputo la risposta, non avrei postato la domanda. :) – Andy