I am pretty new to multi-threading in general and I would like to know how can I lock a shared integer variable to not be accessed by other threads while it is read/updated by an other thread.
When I try do do SyncLock myInteger
, I get that error : Error 6 'SyncLock' operand cannot be of type 'Integer' because 'Integer' is not a reference type.
Here a simplified example of what I mean
Private Shared myInteger As Integer
Private Sub MySub()
SyncLock myInteger ' This does not work
' read/write a new value to myInteger
End SyncLock
End Sub
MySub is called by multiple instances of the class, and running in multiple threads