Can you please give a full sample ?
It is already a full sample; it is really just one line of code.
Addtional see https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.privatememorysize64?view=net-9.0
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
In maui version 8 there is a problem when moving pages the memory not release.
I would like to ask how to observe the RAM and if it pass threshold x it will be presanted
in UI label in red color, otherwise in green color.
Use MVVM approach.
Thanks,
Update
You can also add message to end user that block the UI that RAM consuption pass threshold.
Can you please give a full sample ?
It is already a full sample; it is really just one line of code.
Addtional see https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.privatememorysize64?view=net-9.0
System.Diagnostics.PerformanceCounter _ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
var ramCapacity = GetTotalMemoryInGb();
var ramUsageInPercenatages = ((ramCapacity - (_ramCounter.NextValue() / (1024D)))/ramCapacity)*100;
private static ulong GetTotalMemoryInGb()
{
ulong capacityGB = 0;
try
{
var query = "SELECT Capacity FROM Win32_PhysicalMemory";
var searcher = new ManagementObjectSearcher(query);
foreach (var WniPART in searcher.Get())
{
var capacity = Convert.ToUInt64(WniPART.Properties["Capacity"].Value);
var capacityKB = capacity / 1024;
var capacityMB = capacityKB / 1024;
capacityGB = capacityMB / 1024;
}
return capacityGB;
}
catch (Exception ex)
{
_logger.Error("GetTotalMemoryInGb", ex);
return capacityGB;
}
}