我是写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(..)呢????
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(..)呢????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货