RunCat365 icon indicating copy to clipboard operation
RunCat365 copied to clipboard

CPU always shows 0% when installed from Microsoft Store (MSIX sandbox)

Open octalparrot opened this issue 8 months ago • 9 comments

Bug Description

When RunCat365 is installed from the Microsoft Store, CPU usage always displays 0%. The cat animation runs at minimum speed and the tooltip shows "CPU: 0.0%".

Root Cause

The app uses PerformanceCounter("Processor", "% Processor Time", "_Total") to read CPU usage. Microsoft Store apps run inside an MSIX sandbox which restricts access to Windows Performance Counters. The PerformanceCounter constructor does not throw an exception, but NextValue() always returns 0.

Proposed Fix

Replace PerformanceCounter with the Win32 GetSystemTimes API via P/Invoke (kernel32.dll), which works correctly inside the MSIX sandbox.

The approach:

  • Call GetSystemTimes which returns idle, kernel, and user times as FILETIME values
  • Calculate CPU usage from the delta between consecutive samples
  • Note: kernelTime from GetSystemTimes includes idle time, so actual kernel usage = kernelDelta - idleDelta
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetSystemTimes(
    out long idleTime,
    out long kernelTime,
    out long userTime);

This removes the dependency on System.Diagnostics.PerformanceCounter for CPU monitoring while keeping the same CPUInfo struct and averaging logic.

I have tested this fix locally on Windows 11 and confirmed it reports correct CPU usage.

Environment

  • Windows 11 (10.0.26100)
  • RunCat365 installed from Microsoft Store
  • .NET 9.0

octalparrot avatar Mar 23 '26 08:03 octalparrot

@octalparrot Is this issue the same as the existing, resolved issue (https://github.com/Kyome22/RunCat365/issues/293)?

Kyome22 avatar Mar 29 '26 02:03 Kyome22

@octalparrot Also, since this issue does not follow the Bug issue template, we will not be addressing it.

Kyome22 avatar Mar 29 '26 02:03 Kyome22

is this resolved?

Anandb71 avatar Apr 04 '26 11:04 Anandb71

I haven't received a response, so I'm not sure what's going on.

Kyome22 avatar Apr 04 '26 12:04 Kyome22

I haven't received a response, so I'm not sure what's going on.

I guess we close ? since no updates since and issue seems to be addressed already.

Anandb71 avatar Apr 08 '26 15:04 Anandb71

Is this issue the same as the existing, resolved issue (https://github.com/Kyome22/RunCat365/issues/293)?

I'd say it is the same problem, but he's suggesting a different solution. A solution that requires less action from the user, but on the other hand requires more effort from the developers.

mor39a avatar Apr 09 '26 01:04 mor39a

@octalparrot I am closing this issue. Please re-open it if you would like to continue the discussion.

Kyome22 avatar Apr 20 '26 16:04 Kyome22

@Kyome22 Should we close the related PR?

mor39a avatar Apr 20 '26 19:04 mor39a

@mor39a Yes, we should.

Kyome22 avatar Apr 21 '26 02:04 Kyome22