Basically I have a global variable, such as...
Dim int1 as integer
And then I have two asynchronous functions, such as...
function bleh()
int1 += 1
end function
and
function Meh()
int1 -= 1
end function
Both these functions are being run by Task.Run().
I want to use SyncLock in both these functions. However, all the examples given on the MSDN site only show examples of SyncLock being used within a single function. So I can't tell simply from the MSDN description if it is "okay" for me to use SyncLock across two different functions, on a global variable.
What I want to do is something like this:
Private Shared SyncObj as Object '<-- global
Dim int1 as integer '<-- global
Sub Form_Load(...)
SyncObj = new Object
Task.Run(Function() bleh())
Task.Run(Function() Meh())
End Sub
Function bleh()
SyncLock SyncObj
int1 += 1
End SyncLock
End Function
Function Meh()
SyncLock SyncObj
int1 -= 1
End SyncLock
End Function
Is this okay to do? Will bleh() block Meh() from changing int1, and vise versa? Thanks! Sorry for the VB lol.