请问用vb.net怎么样实现单件模式中的double check
我是写c#的,VB.net不会写。
Public ReadOnly Property CachedTables(ByVal context As CallContext) As Cache.CachedTableCollection
Get
Dim siteTableList As SiteCachedTables = Nothing
SyncLock _cachedTablesDictionary
If Not _cachedTablesDictionary.TryGetValue(context.SiteCode, siteTableList) Then
siteTableList = CType(System.Threading.Thread.VolatileRead(New SiteCachedTables(context.SiteCode, _host.GetTableList(context))), SiteCachedTables)
_cachedTablesDictionary.Add(context.SiteCode, siteTableList)
End If
End SyncLock
......
End Get
End Property
这样在多线程的情况还是有问题,估计我写的这个:VolatileRead 就不对。
VB.net中查了一下,没有Volatile这个关键字。那么这里我如何控制:_cachedTablesDictionary.Add(..)呢????