首页 > 代码库 > 上传程序Dictionary 字典 哈希--多读一写锁ReaderWriterLock
上传程序Dictionary 字典 哈希--多读一写锁ReaderWriterLock
//上传程序Dictionary 字典 哈希/// <summary>/// 车辆控制信息哈斯表,Key是终端号,Value是车辆信息控制对象/// </summary>private Dictionary<string, MsgObject> _MsgObjectHashMap = new Dictionary<string, MsgObject>();public Dictionary<string, MsgObject> MsgObjectHashMap { get { return _MsgObjectHashMap; } }//用法//判断是否包含if (LogicManager.MsgObjectHashMap.ContainsKey(key)){MsgObject controlObject = LogicManager.MsgObjectHashMap[key];//删除LogicManager.MsgObjectHashMap.Remove(key);//处理之后移除 //添加if (!LogicManager.MsgObjectHashMap.ContainsKey(msgObjeKey)){LogicManager.MsgObjectHashMap.Add(msgObjeKey, controlObject);}-----------/// <summary>/// 连接列表/// </summary>public Dictionary<string, CAPacket> CaSessionTable = new Dictionary<string, CAPacket>();//读写锁/// <summary>/// 车辆控制信息哈斯表锁/// </summary>private ReaderWriterLock _MsgObjectHashMapLock = new ReaderWriterLock();public ReaderWriterLock MsgObjectHashMapLock { get { return _MsgObjectHashMapLock; } }//用法:LogicManager.DriverInfoHashMapLock.AcquireReaderLock(5000);//设定5000毫秒 获取读锁if (LogicManager.DriverInfoHashMapLock.IsReaderLockHeld) //判断一下在释放锁{LogicManager.DriverInfoHashMapLock.ReleaseLock(); //或.ReleaseReaderLock();}//更新驾驶员信息LogicManager.DriverInfoHashMapLock.AcquireWriterLock(5000);if (LogicManager.DriverInfoHashMapLock.IsWriterLockHeld){LogicManager.DriverInfoHashMapLock.ReleaseWriterLock();}
上传程序Dictionary 字典 哈希--多读一写锁ReaderWriterLock
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。