I've got this code
The GetContextCallBack is multi-threaded.Code:Public Class Form1 Dim m_listener As HttpListener = Nothing Dim m_asyncCount As Integer = 0 Private Sub GetContextCallBack(ByVal result As IAsyncResult) 'Dim listener As HttpListener = CType(result.AsyncState, HttpListener) m_asyncCount += 1 Dim acHold As Integer = m_asyncCount DisplayInfo("In Callback with " & m_asyncCount.ToString & "...")
I am incrementing m_asyncCount but when I went to use it later in the GetContextCallback function it was sometimes "incremented" a second time by the call back running again while this one waited to complete (some take longer - they process large memory streams).
At any rate I put the acHold in place to hold the value - and it works...
But I'm leary to do it this way - as I've already seen it can step on it's own toes.
Is there a way to use a DELEGATE to accomplish this in a cleaner fashion?
Ultimately I believe I'm going to get the sequential # from an identity column in a database INSERT - but wanted to test out my proof-in-concept before I got to that point...




Reply With Quote