C# 条目抛出索引超出范围异常

C# 条目抛出索引超出范围异常,c#,C#,下一行 EventLogEntry[] entries = _eventLog.Entries.Cast<EventLogEntry>().ToArray(); 我们有时会得到一个索引异常 System.Diagnostics.EventLogInternal.IntFrom(Byte[] buf, Int32 offset) System.Diagnostics.EventLogInternal.GetCachedEntryPos(Int32 entryIndex) System

下一行

EventLogEntry[] entries = _eventLog.Entries.Cast<EventLogEntry>().ToArray();
我们有时会得到一个索引异常

System.Diagnostics.EventLogInternal.IntFrom(Byte[] buf, Int32 offset)
System.Diagnostics.EventLogInternal.GetCachedEntryPos(Int32 entryIndex)
System.Diagnostics.EventLogInternal.GetEntryWithOldest(Int32 index)
System.Diagnostics.EventLogInternal.GetEntryAtNoThrow(Int32 index) 
System.Diagnostics.EventLogEntryCollection.EntriesEnumerator.MoveNext()
System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1 source)
System.Linq.Enumerable.ToArray(TSource)(IEnumerable`1 source)
System.Diagnostics.EventLogInternal.IntFrom(字节[]buf,Int32偏移量)
System.Diagnostics.EventLoginInternal.GetCachedEntryPos(Int32 entryIndex)
System.Diagnostics.EventLoginInternal.GetEntryWithOlested(Int32索引)
System.Diagnostics.EventLoginInternal.GetEntryAtNoThrow(Int32索引)
System.Diagnostics.EventLogEntryCollection.EntriesEnumerator.MoveNext()
System.Linq.Enumerable.d_ub1`1.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1源)
System.Linq.Enumerable.ToArray(TSource)(IEnumerable`1源)
我们使用它来创建某种Logviewer,它不绑定到运行它的机器上。 只能从单个trhead访问对象

我的猜测是,有时会出现“种族状况”。
当您查看时,很明显,在访问枚举器时删除条目可能是导致异常的原因。

条目数量是否可能太多?您是否同时读取和写入
事件日志?@T\u D定义“太大”。是否有某个值?21亿^^^请参见@YuvalItzchakov您指的是事件日志的实例还是真正的evetnlog?它只是一个观众。
System.Diagnostics.EventLogInternal.IntFrom(Byte[] buf, Int32 offset)
System.Diagnostics.EventLogInternal.GetCachedEntryPos(Int32 entryIndex)
System.Diagnostics.EventLogInternal.GetEntryWithOldest(Int32 index)
System.Diagnostics.EventLogInternal.GetEntryAtNoThrow(Int32 index) 
System.Diagnostics.EventLogEntryCollection.EntriesEnumerator.MoveNext()
System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
System.Linq.Buffer`1..ctor(IEnumerable`1 source)
System.Linq.Enumerable.ToArray(TSource)(IEnumerable`1 source)