asyncronous method call

  • Thread starter Thread starter Allan Ebdrup
  • Start date Start date
A

Allan Ebdrup

I'm inside a function where I have a static cache, when the cache needs to
be updated I want to do it asyncronously, because updating the cache takes a
while. I want to use thread safety when writing and reading the cache (a
Mutex?)

Private Function Count(ByVal Guid)As Int32
Static Dim countResults As Hashtable = New Hashtable
Static Dim countResultTimestamps As Hashtable = New Hashtable
'Here I want to call CacheUpdateCount(countResults,
countResultTimestamps, Guid) in a new asyncronous thread updating the static
cache
Return countResults(Guid)
End function

Private Function CacheUpdateCount(ByRef countResults As Hashtable, ByRef
countResultTimestamps As Hashtable, ByVal Guid)
'Update static cache
end function

1 ) How do I spawn a new thread calling the CacheUpdateCount() method?
2) How do I ensure that I don't read and write the cache at the same time?

Kind Regards,
Allan Ebdrup
 
Allan Ebdrup said:
I'm inside a function where I have a static cache, when the cache needs to
be updated I want to do it asyncronously, because updating the cache takes
a while. I want to use thread safety when writing and reading the cache (a
Mutex?)

Private Function Count(ByVal Guid)As Int32
Static Dim countResults As Hashtable = New Hashtable
Static Dim countResultTimestamps As Hashtable = New Hashtable
'Here I want to call CacheUpdateCount(countResults,
countResultTimestamps, Guid) in a new asyncronous thread updating the
static cache
Return countResults(Guid)
End function

Private Function CacheUpdateCount(ByRef countResults As Hashtable, ByRef
countResultTimestamps As Hashtable, ByVal Guid)
'Update static cache
end function

1 ) How do I spawn a new thread calling the CacheUpdateCount() method?
2) How do I ensure that I don't read and write the cache at the same time?

Kind Regards,
Allan Ebdrup

Please post VB related questions to the microsoft.public.dotnet.languages.vb
NG.

Willy.
 
Back
Top