If I am using a synchronized hashtable, do I still need to useSyncLock ?

  • Thread starter Thread starter fniles
  • Start date Start date
F

fniles

If I am using a synchronized hashtable, do I still need to use
SyncLock ?
Thank you

Friend g_htCommoditys As Hashtable
Friend g_htSyncCommoditys As Hashtable
Friend CommodityLock As New Object

g_htCommoditys = New Hashtable
g_htSyncCommoditys = Hashtable.Synchronized(g_htCommoditys)

SyncLock CommodityLock ---> Is this SyncLock still needed here ?
If Not (g_htSyncCommoditys.Contains(sSymbol)) Then
Dim sCommodity(COMM_MAX) As String
sCommodity(COMM_SYMBOL) = "A"
sCommodity(COMM_OPEN) = "08:30"
g_htSyncCommoditys.Add(sSymbol, sCommodity)
End If
End SyncLock
 
If I am using a synchronized hashtable, do I still need to use
SyncLock ?
Thank you

Friend g_htCommoditys As Hashtable
Friend g_htSyncCommoditys As Hashtable
Friend CommodityLock As New Object

g_htCommoditys = New Hashtable
g_htSyncCommoditys = Hashtable.Synchronized(g_htCommoditys)

SyncLock CommodityLock ---> Is this SyncLock still needed here ?
If Not (g_htSyncCommoditys.Contains(sSymbol)) Then
Dim sCommodity(COMM_MAX) As String
sCommodity(COMM_SYMBOL) = "A"
sCommodity(COMM_OPEN) = "08:30"
g_htSyncCommoditys.Add(sSymbol, sCommodity)
End If
End SyncLock

According to MSDN docs, yes, you still need to SyncLock your
collection in order to guarentee collection modification prevention
against other threads.

See "Remarks":
http://msdn.microsoft.com/en-us/library/system.collections.hashtable.synchronized.aspx

HTH,

Onur Güzel
 
Back
Top