private void AppendIP(string ip) { List <IpItem> lst = IPList; lock (lst) { DateTime now = DateTime.Now; IpItem nitem = new IpItem(); nitem.UpdateDate = now; nitem.IP = ip; lst.Add(nitem); } }
/// <summary> /// 删除过期IP /// </summary> private int DeleteOld() { List <IpItem> lst = IPList; int ret = 0; lock (lst) { DateTime now = DateTime.Now; IpItem item = null; for (int i = lst.Count - 1; i >= 0; i--) { item = lst[i]; if (now.Subtract(item.UpdateDate).TotalMilliseconds > IPTimeOutMilliseconds) { lst.RemoveAt(i); } } } return(ret); }