/// <summary> /// 处理超时请求 /// </summary> public virtual void RequestTimeOutHandle() { while (RequestOutTimeQueue.Count > 0) { if (RequestOutTimeQueue.TryPeek(out RequestKeyTime keyTime)) { long outtime = RequestOutTime * 10000; if ((TimeHelper.GetTime() - keyTime.Time) > outtime) { if (RequestOutTimeQueue.TryDequeue(out keyTime)) { if (AsyncResultDict.ContainsKey(keyTime.Key)) { Task.Factory.StartNew(() => { AsyncBackResult(new Result() { Id = keyTime.Key, ErrorMsg = "time out", ErrorId = (int)ErrorType.TimeOut }); }); } } } else { break; } } else { break; } } }
/// <summary> /// 添加异步回调到表中 /// </summary> /// <param name="Ids"></param> /// <returns></returns> protected virtual ManualResetValueTaskSource <Result> AddAsyncResult(long ids) { ManualResetValueTaskSource <Result> asyncResult = new ManualResetValueTaskSource <Result>(); if (!AsyncResultDict.TryAdd(ids, asyncResult)) { Log.InfoFormat("add async back have id:{ids}", ids); AsyncResultDict[ids] = asyncResult; } if (RequestOutTime > 0) { RequestOutTimeQueue.Enqueue(new RequestKeyTime(ids, TimeHelper.GetTime())); } return(asyncResult); }