asyncronous method call

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan Ebdrup

    asyncronous method call

    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 countResultTime stamps As Hashtable = New Hashtable
    'Here I want to call CacheUpdateCoun t(countResults,
    countResultTime stamps, Guid) in a new asyncronous thread updating the static
    cache
    Return countResults(Gu id)
    End function

    Private Function CacheUpdateCoun t(ByRef countResults As Hashtable, ByRef
    countResultTime stamps As Hashtable, ByVal Guid)
    'Update static cache
    end function

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

    Kind Regards,
    Allan Ebdrup


  • Willy Denoyette [MVP]

    #2
    Re: asyncronous method call


    "Allan Ebdrup" <comaeb@ofir.co m> wrote in message
    news:ORlL9z7VFH A.3488@tk2msftn gp13.phx.gbl...[color=blue]
    > 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 countResultTime stamps As Hashtable = New Hashtable
    > 'Here I want to call CacheUpdateCoun t(countResults,
    > countResultTime stamps, Guid) in a new asyncronous thread updating the
    > static cache
    > Return countResults(Gu id)
    > End function
    >
    > Private Function CacheUpdateCoun t(ByRef countResults As Hashtable, ByRef
    > countResultTime stamps As Hashtable, ByVal Guid)
    > 'Update static cache
    > end function
    >
    > 1 ) How do I spawn a new thread calling the CacheUpdateCoun t() method?
    > 2) How do I ensure that I don't read and write the cache at the same time?
    >
    > Kind Regards,
    > Allan Ebdrup
    >[/color]

    Please post VB related questions to the microsoft.publi c.dotnet.langua ges.vb
    NG.

    Willy.


    Comment

    Working...