我有一个包含许多 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 { }
}
}
}