ConcurrentQueue.First()
if (myConcurrentQueue.IsEmpty)
{
//do nothing
}
else
{
try
{
sdFirst = myConcurrentQueue.First();
}
catch (InvalidOperationException ex)
{
Debug.WriteLine("myConcurrentQueue.Count: " + myConcurrentQueue.Count);
}
}
The above code occasionally throws the following exception:
System.InvalidOperationException: Sequence contains no elements
Stack Trace:
at System.Linq.Enumerable.First[TSource](IEnumerable`1) + 0x43
When the exception is thrown, myConcurrentQueue.Count is well above zero (e.g., 6, 10).
Could anyone shed some light on this?