Synclock

manJ123

Member
Joined
Jul 23, 2008
Messages
6
Programming Experience
Beginner
Hi can someone please help

I have two threads that access the same class at the same time to different things, which has been causing problems. I have been trying to use the synclock statement to resolve this, but i dont think im using it correctly as every now and then both threads manage to execute the synclock statement causing a deadlock. Am i doing something wrong I though that it is impossible for one thread to execute the synclock statement if another one already has the lock.

The method below gets called by two seperate threads. One to remove the eventhandler when the form is closing and the other to update the screen with a price triggered by another class
VB.NET:
    Private Shared lockObject As New Object

    Private Sub route(ByVal _LTP As String, ByVal _tickerBloomCode As String, ByVal isRoute As Boolean)

        SyncLock lockObject
            If isRoute Then
                Call updatePrice(_LTP, _tickerBloomCode)
            Else
                RemoveHandler LTP_Event2, AddressOf route
            End If
        End SyncLock

    End Sub

Any help or thoughts would be much appreciated
 
Back
Top