Is this code correct or is there any possibility of some random threading deadlocks etc?
Is it a good idea to use static properties and locking together? Or is static property thread-safe anyway?
Private Shared _CompiledRegExes As List(Of Regex)
Private Shared Regexes() As String = {"test1.Regex", "test2.Regex"}
Private Shared RegExSetupLock As New Object
Private Shared ReadOnly Property CompiledRegExes() As List(Of Regex)
Get
If _CompiledRegExes Is Nothing Then
SyncLock RegExSetupLock
If _CompiledRegExes Is Nothing Then
_CompiledRegExes = New List(Of Regex)(Regexes.Length - 1)
For Each exp As String In Parser.Regexes
_CompiledRegExes.Add(New Regex(exp, RegexOptions.Compiled Or RegexOptions.CultureInvariant Or RegexOptions.IgnoreCase))
Next
End If
End SyncLock
End If
Return _CompiledRegExes
End Get
End Property
If it's not obvious code is compiling regexes and storing in a List(Of Regex) so they can run faster. And it's shared so every instance of class can get benefit out of it.