public MsgInformation WaitForInformation(MsgInformationEx MsgDTO, string msg, Predicate <MsgInformation> judgeFunc, int timeout = 7, bool isNeedAt = false) { var signal = new AutoResetEvent(false); var unit = new WaiterUnit { JudgePredicate = judgeFunc, Signal = signal }; lock (_lockObj) { if (UnitsDic.ContainsKey(MsgDTO.FromGroup)) { UnitsDic[MsgDTO.FromGroup].Add(unit); } else { UnitsDic.Add(MsgDTO.FromGroup, new List <WaiterUnit>() { unit }); } } MsgSender.PushMsg(MsgDTO, msg, isNeedAt); signal.WaitOne(timeout * 1000); lock (_lockObj) { unit = UnitsDic[MsgDTO.FromGroup].FirstOrDefault(u => u.Id == unit.Id); UnitsDic[MsgDTO.FromGroup].Remove(unit); } return(unit?.ResultInfos.FirstOrDefault()); }
public MsgInformation WaitForInformation(MsgCommand command, Predicate <MsgInformation> judgeFunc, int timeout = 7) { var signal = new AutoResetEvent(false); var unit = new WaiterUnit { JudgePredicate = judgeFunc, Signal = signal }; lock (_lockObj) { if (UnitsDic.ContainsKey(command.ToGroup)) { UnitsDic[command.ToGroup].Add(unit); } else { UnitsDic.Add(command.ToGroup, new List <WaiterUnit>() { unit }); } } MsgSender.PushMsg(command); signal.WaitOne(timeout * 1000); lock (_lockObj) { unit = UnitsDic[command.ToGroup].FirstOrDefault(u => u.Id == unit.Id); UnitsDic[command.ToGroup].Remove(unit); } return(unit?.ResultInfos.FirstOrDefault()); }
public void Send() { var content = MsgList.JoinToString("\r\n"); MsgSender.PushMsg(GroupNum, QQNum, content, BindAi); }