110,538
社区成员
发帖
与我相关
我的任务
分享
//用于存放SOCKET与关联的信息
static IDictionary<Socket, SomeInfo> dic = new Dictionary<Socket, SomeInfo>();
//删除的代码,放在一个timer中,1秒检查一次
for(int i=0;i<list.Count;i++)
{
var socket = list[i];
Console.WriteLine(socket.Handle);
socket.Disconnect(false);
Console.WriteLine("before:" + dic.ContainsKey(socket) + " count:" + dic.Keys.Count);
Console.WriteLine( dic.Remove(socket) );
Console.WriteLine("after:" + dic.ContainsKey(socket) + " count:" + dic.Keys.Count);
}
System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>