需要一个LinkedList(T的) [英] Need a Syncroot for a LinkedList(of T)
问题描述
我使用VB.Net,并希望使用LinkedList。只有问题是它是一个多线程应用程序。我从MSDN看到Syncroot是ICollection接口的显式实现。我发现人们想要做类似的事情与List(Of T)。看来,解决方案是将列表转换到接口。
I am using VB.Net and would like to use a LinkedList. Only problem is that it is a multithreaded application. I saw from MSDN that Syncroot is an explicit implementation of the ICollection Interface. I found people wanting to do similar things with List(Of T). It seems that the solution there is to cast the list to the interface.
我试图做我想象的是一个类似的东西在VB.Net,基本上:
I have tried to do what I would imagine to be a similar thing in VB.Net, basically:
Dim TestLinkedList = New LinkedList(Of Long)
SyncLock (Ctype(TestLinkedList, ICollection)).SyncRoot
.
.
.
End SyncLock
以上是否正确?
推荐答案
它会工作,这是所有可以说的。 SyncRoot是.NET 1.1的一个错误,没有理由继续练习。
It will work, that's about all that can be said for it. SyncRoot was a mistake from .NET 1.1, there's no reason to continue the practice.
Dim list = New LinkedList(Of Long)
Dim listLock = New Object
...
SyncLock(listLock)
...
End SyncLock
这篇关于需要一个LinkedList(T的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!