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

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
 
O

Onur Güzel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top