为什么我的线程安全通用集合不尊重我的枚举器? [英] Why My Thread Safe Generic Collection not Respect My Enumerator ?

查看:77
本文介绍了为什么我的线程安全通用集合不尊重我的枚举器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个从IList(OF T)继承的线程安全集合,并且还编写了一个从IEnumerator(Of T)继承的Enumerator,下面的代码显示了GetEnumerator方法



I have wrote a a thread safe collection inherited from IList(OF T) and and also wrote an Enumerator Inherited from IEnumerator(Of T), the below code shows the GetEnumerator Method

Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
    Dim value As IEnumerator(Of T) = CType(Nothing, IEnumerator(Of T))
    SyncLock Me._lock
        ' Why My collection not respect my Enumerator.......??????????????
        value = New RiverNileListEnumerator(Me)

    End SyncLock
    Return value
End Function





在测试集合期间,发现它返回No值但是当我用InnerList(List(Of T)枚举器替换My-Enumerator时,该集合将适用于For Each Statement。





During testing the collection, found that it returns No values but when I did replace My-Enumerator with the InnerList (List(Of T) Enumerator the collection will works fine with For Each Statement.

' the collection works fine with this value
          value = Me.InnerList.GetEnumerator()





任何建议都将是赞赏。谢谢



any advice will be appreciated. Thanks

推荐答案

我得到答案,我将用于这样的每个陈述



I get the answer, i shall use for each statement like this

For Each obj As object In objects.ToArray()
       foo.Items.Add(obj)
   Next


这篇关于为什么我的线程安全通用集合不尊重我的枚举器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆