Description
Description
my program have the code: var counterNames = new PerformanceCounterCategory("GPU Engine").GetInstanceNames();
if the SystemSetting.exe is suspended before my program run above code, will have exception:System.InvalidOperationException: Category does not exist.
And I call var c = PerformanceCounterCategory.GetCategories();, when SystemSetting.exe is suspended, will get 60 categories, not including "GPU Engine", while when SystemSetting.exe is not suspened, will get 206 categories, including "GPU Engine".
So why this happen , and how should I handle this? now I have 2 sollutions: 1, kill the suspened SystemSetting.exe , 2, maybe use C++ instead, but that's difficult.
Reproduction Steps
OS is Windows 11 prof 22H2 22621.3007. need firstly make the 'SystemSettings.exe' is suspended in task manager,and then start the test program. two ways to suspend 'SystemSettings.exe' :
1, open setting application(installed with Win11), and minimize it.
or 2, Logout the account and login, or restart the PC, after about 2 minutes, the 'SystemSettings.exe' will be launched automatically by the system and suspended.
Expected behavior
var counterNames = new PerformanceCounterCategory("GPU Engine").GetInstanceNames(); can always run OK with out execption,
and var c = PerformanceCounterCategory.GetCategories() can always get all the categories including "GPU Engine", whether SystemSetting.exe is suspended or not.
Actual behavior
when SystemSetting.exe is suspended before the program run, var counterNames = new PerformanceCounterCategory("GPU Engine").GetInstanceNames(); will have execption System.InvalidOperationException: Category does not exist.
and var c = PerformanceCounterCategory.GetCategories() only gets part of the categories, without "GPU Engine".
Regression?
No response
Known Workarounds
kill the suspended SystemSetting.exe before execute the above codes var counterNames = new PerformanceCounterCategory("GPU Engine").GetInstanceNames()
Configuration
No response
Other information
OS is Windows 11 prof 22H2 22621.3007. .NetFramework 4.6.2, 4.7.2, 4.8 .