diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig
index 2ea8e052b1e..e0ed0f48186 100644
--- a/src/Microsoft.DotNet.Wpf/src/.editorconfig
+++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig
@@ -135,9 +135,6 @@ dotnet_diagnostic.CA1859.severity = suggestion
# CA2011: Do not assign property within its setter
dotnet_diagnostic.CA2011.severity = suggestion
-# CA2019: ThreadStatic fields should not use inline initialization
-dotnet_diagnostic.CA2019.severity = suggestion
-
# Should change all internal IntPtr/UIntPtr to nint/uint. IntPtr/UIntPtr no
# longer do checked operations so they are now equivalent.
# CA2020: Prevent behavioral change caused by built-in operators of IntPtr/UIntPtr
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Win32/UnsafeNativeMethodsPenimc.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Win32/UnsafeNativeMethodsPenimc.cs
index e5c1385bcb6..1b54009af18 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Win32/UnsafeNativeMethodsPenimc.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Win32/UnsafeNativeMethodsPenimc.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -64,7 +64,7 @@ internal static class UnsafeNativeMethods
/// Whether or not the WISP Tablet Manager server object has been locked in the MTA.
///
[ThreadStatic]
- private static bool _wispManagerLocked = false;
+ private static bool _wispManagerLocked;
[ThreadStatic]
private static IPimcManager3 _pimcManagerThreadStatic;
@@ -73,7 +73,7 @@ internal static class UnsafeNativeMethods
/// The cookie for the PenIMC activation context.
///
[ThreadStatic]
- private static IntPtr _pimcActCtxCookie = IntPtr.Zero;
+ private static IntPtr _pimcActCtxCookie;
#endregion
@@ -132,10 +132,8 @@ internal static IPimcManager3 PimcManager
{
get
{
- if (_pimcManagerThreadStatic == null)
- {
- _pimcManagerThreadStatic = CreatePimcManager();
- }
+ _pimcManagerThreadStatic ??= CreatePimcManager();
+
return _pimcManagerThreadStatic;
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/TipTsfHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/TipTsfHelper.cs
index dfee204f7cb..dd86a50209a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/TipTsfHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Interop/TipTsfHelper.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -42,7 +42,7 @@ internal static class TipTsfHelper
/// Cache any in progress operation in case we get multiple calls.
///
[ThreadStatic]
- private static DispatcherOperation s_KbOperation = null;
+ private static DispatcherOperation s_KbOperation;
///
/// If DispatcherProcessing is disabled, this will BeginInvoke the appropriate KB operation
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs
index 3d6abd836dc..650139afd3b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -218,7 +218,7 @@ internal static bool IsPointerStackEnabled
/// thread as there is one per specific touch stack InputProvider.
///
[ThreadStatic]
- private static StylusLogic _currentStylusLogic = null;
+ private static StylusLogic _currentStylusLogic;
///
/// This property is backed by a ThreadStatic instance. This will be instantiated
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs
index 59851be31cc..5a6d4ae3308 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -236,7 +236,7 @@ internal bool DownHandled
#region Member Variables
[ThreadStatic]
- private static int _activeDeviceCount = 0;
+ private static int _activeDeviceCount;
private TouchAction _lastAction = TouchAction.Move;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs
index 9163575f79c..0a62db15e72 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs
@@ -2429,7 +2429,7 @@ private object RunDispatcher(object ignore)
// Keep LoadBamlSyncInfo stack so that the Outer LoadBaml and Inner LoadBaml( ) for the same
// Uri share the related information.
[ThreadStatic]
- private static Stack s_NestedBamlLoadInfo = null;
+ private static Stack s_NestedBamlLoadInfo;
private Uri _startupUri;
private Uri _applicationMarkupBaseUri;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs
index 5b8d4192ea7..bcf9b8e1d2a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs
@@ -2280,7 +2280,7 @@ internal static ResourceKey ToolBarMenuStyleKey
private SystemResourceKeyID _id;
[ThreadStatic]
- private static SystemResourceKey _srk = null;
+ private static SystemResourceKey _srk;
#endif
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs
index 6c52eb03a9a..68b8d7abb10 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/TextSearchInternal.cs
@@ -846,10 +846,8 @@ private static DummyObject DummyElement
{
get
{
- if (_dummyElement == null)
- {
- _dummyElement = new DummyObject();
- }
+ _dummyElement ??= new DummyObject();
+
return _dummyElement;
}
}
@@ -889,7 +887,7 @@ private static CultureInfo GetCulture(DependencyObject element)
private DispatcherTimer _timeoutTimer;
[ThreadStatic]
- private static DummyObject _dummyElement = new DummyObject();
+ private static DummyObject _dummyElement;
#endregion
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs
index 8f85d05c952..685b12d711d 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Freezable.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -475,21 +475,16 @@ protected virtual bool FreezeCore(bool isChecking)
// FireChanged occurs.
//
[ThreadStatic]
- static private EventStorage _eventStorage = null;
+ private static EventStorage _eventStorage;
///
/// Property to access and intialize the thread static _eventStorage variable.
///
- private EventStorage CachedEventStorage
+ private static EventStorage CachedEventStorage
{
get
{
- // make sure _eventStorage is not null - with ThreadStatic it appears that the second
- // thread to access the variable will set this to null
- if (_eventStorage == null)
- {
- _eventStorage = new EventStorage(INITIAL_EVENTSTORAGE_SIZE);
- }
+ _eventStorage ??= new EventStorage(INITIAL_EVENTSTORAGE_SIZE);
return _eventStorage;
}