ThreadStatic field initialised inline (CA2019)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key dotnet.codequality.threadstatic-initializer · Severity warning · Category codequality
Microsoft analyzer CA2019. Flags a [ThreadStatic] field with an inline initializer. The initializer runs once, on one thread; every other thread sees the default.
Incorrect
Section titled “Incorrect”[ThreadStatic]private static StringBuilder _buffer = new();Correct
Section titled “Correct”[ThreadStatic]private static StringBuilder? _buffer;
private static StringBuilder Buffer => _buffer ??= new StringBuilder();