SynchronizedEnumerator is dead
This commit is contained in:
parent
5d27ee38a7
commit
5eff62bb5a
@ -1,46 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace ObservableCollections.Internal
|
|
||||||
{
|
|
||||||
internal class SynchronizedEnumerator<T> : IEnumerator<T>
|
|
||||||
{
|
|
||||||
bool isDisposed;
|
|
||||||
readonly object gate;
|
|
||||||
readonly bool lockTaken;
|
|
||||||
readonly IEnumerator<T> enumerator;
|
|
||||||
|
|
||||||
public SynchronizedEnumerator(object gate, IEnumerator<T> enumerator)
|
|
||||||
{
|
|
||||||
this.gate = gate;
|
|
||||||
this.enumerator = enumerator;
|
|
||||||
Monitor.Enter(gate, ref lockTaken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Current => enumerator.Current;
|
|
||||||
|
|
||||||
object IEnumerator.Current => Current!;
|
|
||||||
public bool MoveNext() => enumerator.MoveNext();
|
|
||||||
public void Reset() => enumerator.Reset();
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (!isDisposed)
|
|
||||||
{
|
|
||||||
isDisposed = true;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
enumerator.Dispose();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (lockTaken)
|
|
||||||
{
|
|
||||||
Monitor.Exit(gate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -211,7 +211,13 @@ namespace ObservableCollections
|
|||||||
|
|
||||||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
|
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new SynchronizedEnumerator<KeyValuePair<TKey, TValue>>(SyncRoot, dictionary.GetEnumerator());
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
foreach (var item in dictionary)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
@ -280,7 +280,13 @@ namespace ObservableCollections
|
|||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
public IEnumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new SynchronizedEnumerator<T>(SyncRoot, buffer.GetEnumerator());
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
foreach (var item in buffer)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
@ -139,7 +139,13 @@ namespace ObservableCollections
|
|||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
public IEnumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new SynchronizedEnumerator<T>(SyncRoot, list.GetEnumerator());
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
@ -203,7 +203,13 @@ namespace ObservableCollections
|
|||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
public IEnumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new SynchronizedEnumerator<T>(SyncRoot, queue.GetEnumerator());
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
foreach (var item in queue)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
@ -195,7 +195,13 @@ namespace ObservableCollections
|
|||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
public IEnumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new SynchronizedEnumerator<T>(SyncRoot, buffer.GetEnumerator());
|
lock (SyncRoot)
|
||||||
|
{
|
||||||
|
foreach (var item in buffer)
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user