0
我收到错误 收集已修改;枚举操作可能不会执行。 在System.Collections.Queue.QueueEnumerator.MoveNext()收藏已修改;枚举操作可能不会执行
Queue ReqQ = (Application["ReqQ"] != null) ? ((Queue)Application["ReqQ"]) :
new Queue(50);
if (ReqQ != null)
{
foreach (object OReq in ReqQ)
{
string mId = (string)OReq;
if (mId.Split('~')[1].Equals(reqUid.Split('~')[1]) && (DateTime.Parse(mId.Split('~')[0]).AddMinutes(1 * int.Parse(string.IsNullOrEmpty(delay) ? "0" : delay)) > DateTime.Now))
{
isSuccess = false;
break;
}
}
}
else
{
ReqQ = new Queue(10);
isSuccess = true;
}
if (isSuccess)
{
if (ReqQ.Count >= 10) //only keep last 10 messages in application cache
ReqQ.Dequeue();
ReqQ.Enqueue(reqUid);
Application["ReqQ"] = ReqQ;
}
是的,有多个请求在这个时候使用这个队列。这并不总是发生。一天2-3次。我应该修改哪些代码。 –
@cpsinghal:使用锁定或支持并发访问的集合(如ConcurrentQueue) –