Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Calling functions from threads

$
0
0
Curious - if what I am about to do is thread safe.

I've got this async function running on threads created by httplisteners

Code:

    Private Sub RequestRcvd(ByVal result As IAsyncResult)
        Dim acHold As Integer = System.Threading.Interlocked.Increment(m_asyncCount)
        Dim rtnSize As Long
        Dim blnGetTags As Boolean = False
        If Not m_listener.IsListening Then
            DisplayInfo("", "", "", "", "", "", "", "RequestRcvd", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString, "In Callback with " & acHold.ToString & " (not IsListening)...", "?")
        Else
            Dim context As HttpListenerContext = m_listener.EndGetContext(result)
            m_listener.BeginGetContext(New AsyncCallback(AddressOf RequestRcvd), Nothing)

            Dim request As HttpListenerRequest = context.Request
            Dim cl2 As New FSSerializer
            Dim FSOb As New FSObject(-2)

            Dim returnMessage As String = ""
            Dim response As HttpListenerResponse = Nothing
            Select Case request.Headers("x-package")
                Case "sessionid"
                    Try
                        If cl2.responseStart(request, FSOb, returnMessage) Then
.
.
.
                    Finally
                        If response IsNot Nothing Then
                            response.Close()
                        End If
                    End Try
                Case "actionabc"
                    Try
                        If cl2.responseStart(request, FSOb, returnMessage) Then
.
.
.
                    Finally
                        If response IsNot Nothing Then
                            response.Close()
                        End If
                    End Try
                Case "actionxyz"
                    Try
                        If cl2.responseStart(request, FSOb, returnMessage) Then

And I want to change the code to be

Code:

            Select Case request.Headers("x-package")
                Case "sessionid"
                    rtnStatus = reqSessionId(request, FSOb, returnMessage)
                Case "actionabc"
                    rtnStatus = reqActionABC(request, FSOb, returnMessage)
                Case "actionxyz"
                    rtnStatus = reqActionXYZ(request, FSOb, returnMessage)

Do I have any issues with these reqSessionId and reqActionABC functions being threadsafe?

Is this what STATIC and SHARED is all about? What are the differences between these types of declarations?

I code in so many different languages right now I want to make sure I'm not messing up a silly function declaration at a critical moment.

Thanks!

Viewing all articles
Browse latest Browse all 27554

Trending Articles