File tree Expand file tree Collapse file tree 3 files changed +60
-4
lines changed
Helpers/ItemListDisplayHelpers Expand file tree Collapse file tree 3 files changed +60
-4
lines changed Original file line number Diff line number Diff line change 186
186
<Compile Include =" Helpers\ColorHelpers.cs" />
187
187
<Compile Include =" Helpers\CommonPaths.cs" />
188
188
<Compile Include =" Helpers\FileExtensionHelpers.cs" />
189
+ <Compile Include =" Helpers\ItemListDisplayHelpers\BlockingListEnumerator.cs" />
189
190
<Compile Include =" Helpers\LocalizedEnumHelper.cs" />
190
191
<Compile Include =" Helpers\ResourceHelpers.cs" />
191
192
<Compile Include =" Helpers\FtpHelpers.cs" />
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections ;
3
+ using System . Collections . Generic ;
4
+
5
+ namespace Files . Helpers
6
+ {
7
+ public class BlockingListEnumerator < T > : IEnumerator < T >
8
+ {
9
+ private readonly IList < T > m_Inner ;
10
+ private readonly object m_Lock ;
11
+ private int m_Pos ;
12
+
13
+ public BlockingListEnumerator ( IList < T > inner , object @lock )
14
+ {
15
+ m_Inner = inner ;
16
+ m_Lock = @lock ;
17
+ m_Pos = - 1 ;
18
+ }
19
+
20
+ public T Current
21
+ {
22
+ get
23
+ {
24
+ lock ( m_Lock )
25
+ {
26
+ if ( m_Pos < m_Inner . Count )
27
+ {
28
+ return m_Inner [ m_Pos ] ;
29
+ }
30
+ throw new IndexOutOfRangeException ( ) ;
31
+ }
32
+ }
33
+ }
34
+
35
+ object IEnumerator . Current => Current ;
36
+
37
+ public void Dispose ( )
38
+ {
39
+ }
40
+
41
+ public bool MoveNext ( )
42
+ {
43
+ lock ( m_Lock )
44
+ {
45
+ m_Pos ++ ;
46
+ return m_Pos < m_Inner . Count ;
47
+ }
48
+ }
49
+
50
+ public void Reset ( )
51
+ {
52
+ lock ( m_Lock )
53
+ {
54
+ m_Pos = - 1 ;
55
+ }
56
+ }
57
+ }
58
+ }
Original file line number Diff line number Diff line change @@ -295,10 +295,7 @@ public bool Remove(T item)
295
295
296
296
public IEnumerator < T > GetEnumerator ( )
297
297
{
298
- lock ( syncRoot )
299
- {
300
- return collection . ToList ( ) . GetEnumerator ( ) ;
301
- }
298
+ return new BlockingListEnumerator < T > ( collection , syncRoot ) ;
302
299
}
303
300
304
301
IEnumerator IEnumerable . GetEnumerator ( )
You can’t perform that action at this time.
0 commit comments