Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StyleCleanUp] ThreadStatic fields should not use inline initialization (CA2019) #10301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -64,7 +64,7 @@ internal static class UnsafeNativeMethods
/// Whether or not the WISP Tablet Manager server object has been locked in the MTA.
/// </summary>
[ThreadStatic]
private static bool _wispManagerLocked = false;
private static bool _wispManagerLocked;

[ThreadStatic]
private static IPimcManager3 _pimcManagerThreadStatic;
Expand All @@ -73,7 +73,7 @@ internal static class UnsafeNativeMethods
/// The cookie for the PenIMC activation context.
/// </summary>
[ThreadStatic]
private static IntPtr _pimcActCtxCookie = IntPtr.Zero;
private static IntPtr _pimcActCtxCookie;

#endregion

Expand Down Expand Up @@ -132,10 +132,8 @@ internal static IPimcManager3 PimcManager
{
get
{
if (_pimcManagerThreadStatic == null)
{
_pimcManagerThreadStatic = CreatePimcManager();
}
_pimcManagerThreadStatic ??= CreatePimcManager();

return _pimcManagerThreadStatic;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -42,7 +42,7 @@ internal static class TipTsfHelper
/// Cache any in progress operation in case we get multiple calls.
/// </summary>
[ThreadStatic]
private static DispatcherOperation s_KbOperation = null;
private static DispatcherOperation s_KbOperation;

/// <summary>
/// If DispatcherProcessing is disabled, this will BeginInvoke the appropriate KB operation
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -218,7 +218,7 @@ internal static bool IsPointerStackEnabled
/// thread as there is one per specific touch stack InputProvider.
/// </summary>
[ThreadStatic]
private static StylusLogic _currentStylusLogic = null;
private static StylusLogic _currentStylusLogic;

/// <summary>
/// This property is backed by a ThreadStatic instance. This will be instantiated
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NestedBamlLoadInfo> s_NestedBamlLoadInfo = null;
private static Stack<NestedBamlLoadInfo> s_NestedBamlLoadInfo;

private Uri _startupUri;
private Uri _applicationMarkupBaseUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ internal static ResourceKey ToolBarMenuStyleKey
private SystemResourceKeyID _id;

[ThreadStatic]
private static SystemResourceKey _srk = null;
private static SystemResourceKey _srk;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,8 @@ private static DummyObject DummyElement
{
get
{
if (_dummyElement == null)
{
_dummyElement = new DummyObject();
}
_dummyElement ??= new DummyObject();

return _dummyElement;
}
}
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -475,21 +475,16 @@ protected virtual bool FreezeCore(bool isChecking)
// FireChanged occurs.
//
[ThreadStatic]
static private EventStorage _eventStorage = null;
private static EventStorage _eventStorage;

/// <summary>
/// Property to access and intialize the thread static _eventStorage variable.
/// </summary>
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;
}
Expand Down