
Changes suggested by the Docs Squad: * Modify rule s2178: Update rule description - formalize word selection to clarify the description * Modify rule S2551: capitalize `String` - follow the capitalization of a proper noun, in accordance with the referenced link * Modify rule S3923: improve word choice * Modify rule S2551: capitalize String - `String` is used as a VB `object` in this example. - A new PR will be issued to make a more substantial improvement
39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
include::../why-dotnet.adoc[]
|
|
|
|
The following objects are considered as shared resources:
|
|
|
|
* a reference to https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/me-my-mybase-and-myclass#me[Me]: if the instance is publicly accessible, the lock might be shared
|
|
* a https://learn.microsoft.com/en-us/dotnet/api/system.type[Type] object: if the type class is publicly accessible, the lock might be shared
|
|
* a https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/string-data-type[String] literal or instance: if any other part of the program uses the same string, the lock is shared because of interning
|
|
|
|
== How to fix it
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
Public Sub MyLockingMethod()
|
|
SyncLock Me 'Noncompliant
|
|
' ...
|
|
End SyncLock
|
|
End Sub
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
|
----
|
|
Private lockObj As New Object()
|
|
Public Sub MyLockingMethod()
|
|
SyncLock lockObj
|
|
' ...
|
|
End SyncLock
|
|
End Sub
|
|
----
|
|
|
|
include::../resources-dotnet.adoc[]
|
|
|
|
include::../rspecator.adoc[]
|