private void RFIDNotification_FormClosing(object sender, FormClosingEventArgs e) { lock (moCurrentReadersLock) { foreach (object o in mStoredStates.Keys) { string address = o as string; if (mClients.ContainsKey(address)) { try { MyStoredReaderState rs = mStoredStates[address] as MyStoredReaderState; clsReader reader = mClients[address] as clsReader; if (!reader.IsConnected) { reader.ConnectAndLogin(address, rs.commandPort, rs.userName, rs.password); } restoreReaderState(rs, ref reader); reader.Dispose(); } catch { } } } } }