If you use a Dim variable in a function, no other thread can access this variable, making it thread safe by definition.
However, if you declare it at the class level, you can use SyncLock , which will prevent other threads from accessing it if it is currently being used by others.
Example:
Public Sub AccessVariable() SyncLock Me.dbReader 'Work With dbReader End SyncLock End Sub
source share