diff --git a/src/coreclr/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index 47b1bd454d80e..c727e0d267dcc 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -177,7 +177,7 @@ public static partial class ThreadPool // This needs to be initialized after UsePortableThreadPool above, as it may depend on UsePortableThreadPool and the // config initialization - internal static readonly bool EnableWorkerTracking = GetEnableWorkerTracking(); + private static readonly bool IsWorkerTrackingEnabledInConfig = GetEnableWorkerTracking(); private static unsafe bool InitializeConfigAndDetermineUsePortableThreadPool() { diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs index 70ac108e32d74..1b58668695f03 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs @@ -27,7 +27,7 @@ public static partial class ThreadPool #if CORERT internal const bool EnableWorkerTracking = false; #else - internal static readonly bool EnableWorkerTracking = + private static readonly bool IsWorkerTrackingEnabledInConfig = AppContextConfigHelper.GetBooleanConfig("System.Threading.ThreadPool.EnableWorkerTracking", false); #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs index e0dfdc951cf87..9b4fc5df0395a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @@ -1059,6 +1059,8 @@ public static partial class ThreadPool box.MoveNext(); }; + internal static bool EnableWorkerTracking => IsWorkerTrackingEnabledInConfig && EventSource.IsSupported; + [CLSCompliant(false)] [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle RegisterWaitForSingleObject(