I'm using the following code in a singleton remoting object MBRO. This function is only called on the server side.
''' <summary>
''' Return a cached DataCentricObject
''' </summary>
''' <created_by>CodingBarfield</created_by>
''' <date>04-08-2011</date>
Function DataCentricObjectName(ByVal intID As Integer) As String
Try
SyncLock dictDataCentricObject
If Not dictDataCentricObject.ContainsKey(intID) Then
Dim st As struct = dcLoader.LoadRecord(intID)
dictDataCentricObject(intID) = st.Descript
End If
Return dictDataCentricObject(intID)
End SyncLock
Catch ex As Exception
Throw New Exception("Error in GetTargName", ex)
End Try
End Function
Private dictDataCentricObject As New Dictionary(Of Integer, String)
Dim dcLoader As New DataCentricObject
The LoadRecord function simply reads a line from a database table and copies the fields into a little data structure.
The question
- Is this code multithreading safe (in a remoting environment)
- Are there any performance benefits for different code