G
Guest
The MSDN documentation about the Regex class seems to have contradictory
information. At the "Remarks" section, the documentation states:
"The Regex class is immutable (read-only) and is inherently thread safe.
Regex objects can be created on any thread and shared between threads. "
However, on the "Thread Safety" section of the same class, the documentation
states:
"Any public static (Shared in Visual Basic) members of this type are thread
safe. Any instance members are not guaranteed to be thread safe.".
So, for instance, if i have an instance of Regex and the only method I will
ever call on it is the instance method "IsMatch()", to validate text input,
can I share this instance across different threads? Can multiple threads
concurrently call "IsMatch()" method on this Regex instance without any major
problem? Or do I need to serialize the calls to "IsMatch()" method in this
case, using the "lock" statement?
information. At the "Remarks" section, the documentation states:
"The Regex class is immutable (read-only) and is inherently thread safe.
Regex objects can be created on any thread and shared between threads. "
However, on the "Thread Safety" section of the same class, the documentation
states:
"Any public static (Shared in Visual Basic) members of this type are thread
safe. Any instance members are not guaranteed to be thread safe.".
So, for instance, if i have an instance of Regex and the only method I will
ever call on it is the instance method "IsMatch()", to validate text input,
can I share this instance across different threads? Can multiple threads
concurrently call "IsMatch()" method on this Regex instance without any major
problem? Or do I need to serialize the calls to "IsMatch()" method in this
case, using the "lock" statement?