I have a
VB.Net assembly that is used in an ASP.Net C# app. I have a question about the target object of the SyncLock statement and multi-threading in general.
First question, if I have a Global object (a Public static object in Global.asax.cs) that is passed into a
VB.Net Shared Function as a parameter, should the target object of SyncLock be a locally declared object, or a module level Shared object. Which of the below is the right thing to do?
Shared objSync As Object = New Object
Public Shared Sub DoSomethingElse(GlobalObject as Object)
SyncLock (objSync)
GlobalObject.DoSomething()
End SyncLock
End Sub
Or
Public Shared Sub DoSomethingElse(GlobalObject as Object)
Dim objSync As Object = New Object
SyncLock (objSync)
GlobalObject.DoSomething()
End SyncLock
End Sub
Second question, if I have two concurrent web page requests running in the same ASP.Net session would I need to do any syncronization in the methods (or class constructor) they call if they only called normal instance (Non-Shared) methods? The resource I want to protect in this example is a module level Protected object in the target class.