多数の EventLog オブジェクトを含む Hashtable があります。私の FormClosed イベントでは、これらのオブジェクトを破棄できるようにそれらを反復処理する必要がありますが、最初のキーでフォーカスがフォームに戻り、メソッドが終了しません (フォームが閉じません)。なぜこれを行っているのですか/このアプローチの何が問題なのですか?
private void Main_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
// There will probably be lots of stuff that we'll need to dispose of when closing
if (servers.Count > 0)
{
foreach (string key in servers)
{
try
{
EventLog el = (EventLog)servers[key];
el.Dispose();
}
catch { }
}
}
}