c# - 在控制上连续显示使用的 RAM
问题描述
我有一个过程
Process p = new Process();
p.StartInfo = new ProcessStartInfo("java", -jar test.jar);
我需要获取 RAM,实时process p
使用CPU
我使用了获取 RAM 的代码,但不是实时的:
while(true) {
txtRamIsUsed.Text = BytesToReadableValue(p.PrivateMemorySize64);
}
public string BytesToReadableValue(long number)
{
List<string> suffixes = new List<string> { " B", " KB", " MB", " GB", " TB", " PB" };
for (int i = 0; i < suffixes.Count; i++)
{
long temp = number / (int)Math.Pow(1024, i + 1);
if (temp == 0)
{
return (number / (int)Math.Pow(1024, i)) + suffixes[i];
}
}
return number.ToString();
}
解决方案
推荐阅读
- javascript - 如何使用ngrx状态管理编辑表单数据?错误我得到(尝试区分'[object Object]'时出错。只允许数组和可迭代“))
- php - 如何在 PHP 中读取大型 CSV 文件?
- objective-c - GameCenter 托管类型最多 16 个用户
- botframework - 有没有办法开发自己的 Webchat 而不是 Microsoft Botframework-Webchat
- .net-core - 升级到 .Net Core 2.2 后获取 405 MethodNotAllowed
- excel - 临时存储向量
- arrays - 如何按键获取对象数组中的值
- java - 迁移数据库时合并用户的 Android Room 数据库
- c# - 开发 C# 控制台应用程序以查找所有使用 DirectX 的进程
- java - 执行 joborg.springframework.dao.EmptyResultDataAccessException 时遇到致命错误:结果大小不正确:预期为 1,实际为 0