Collections that are thread safe with

Good Morning all! Some of you know I have started writing a fictional book. Last night I finished up completing the cast of characters the book will use (though I am sure there will be other changes) and thought how I will begin the book. Now if you know any literary agents please send them my way please! If you have enjoyed my writing up to this point. 🙂

Anyway, back to the real world…..We needed to prevent changes being made by other threads when enumerating through our collection. Basically this prevented the threads from making changes while enumerations were occurring. It uses the concept of SyncLock to prevent these changes from being made.

Make it a great day!

Private Sub TimerFired() – happens every 1 second
    Dim x As Integer = 0
    SyncLock MySync.SyncObject
        Do While x <> MyList.Count – 1
            ODC = MyList(x)
            … condition 1: AddToMyList(ODC)
            … condition 2: RemoveFromMyList(x)
            x = x + 1
    End SyncLock
End Sub
Private Sub AddToMyList(var)
    SyncLock MySync.SyncObject
    End SyncLock
End Sub
Private Sub RemoveFromMyList(index)
    SyncLock MySync.SyncObject
    End SyncLock
End Sub

Technorati Tags: ,,,,,,,,,,,,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: