private static long mailNum = 0;//用于标记邮件个数,存储邮件时作为唯一标识 public void RemoveDuplicate() { List <Record> records = null; try { OleDbConnection con = recordDao.Begin(); records = recordDao.FindAllRecords(con); HashSet <string> hs = new HashSet <string>(); foreach (Record record in records) { string myKey = record.M_subject.Trim() + "_" + record.M_mailincometime.ToString(); if (hs.Contains(myKey)) { recordDao.DeleteRecordsByID(con, record.M_id); } else { hs.Add(myKey); } } recordDao.Commit(); } catch (Exception) { recordDao.RollBack(); throw; } finally { recordDao.Close(); } }