Skip to content

Commit

Permalink
fix: resolve cpu and memory component crash (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
HolbyFPV authored Sep 5, 2023
1 parent 49ad62a commit 874cd0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion GlazeWM.Infrastructure/WindowsApi/CpuStatsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ public void Dispose()
/// </summary>
public double GetCpuUsage()
{
return _cpuCounter.Observe();
try
{
return _cpuCounter.Observe();
}
catch
{
return 0;
}
}
}
}
11 changes: 9 additions & 2 deletions GlazeWM.Infrastructure/WindowsApi/MemoryStatsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ public void Dispose()
/// </summary>
public double GetMemoryUsage()
{
var percent = (_physicalBytes - _availableBytes.Observe()) / _physicalBytes;
return percent * 100;
try
{
var percent = (_physicalBytes - _availableBytes.Observe()) / _physicalBytes;
return percent * 100;
}
catch
{
return 0;
}
}
}
}

0 comments on commit 874cd0d

Please sign in to comment.