zoukankan      html  css  js  c++  java
  • 获取系统内存大小(C#)

    代码如下:

            /// <summary>
            
    /// 获取系统内存大小
            
    /// </summary>
            
    /// <returns>内存大小(单位M)</returns>
            private static int GetPhisicalMemory()
            {
                ManagementObjectSearcher searcher 
    = new ManagementObjectSearcher();   //用于查询一些如系统信息的管理对象 
                searcher.Query = new SelectQuery("Win32_PhysicalMemory """new string[] { "Capacity" });//设置查询条件 
                ManagementObjectCollection collection = searcher.Get();   //获取内存容量 
                ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

                
    long capacity = 0;
                
    while (em.MoveNext())
                {
                    ManagementBaseObject baseObj 
    = em.Current;
                    
    if (baseObj.Properties["Capacity"].Value != null)
                    {
                        
    try
                        {
                            capacity 
    += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
                        }
                        
    catch
                        {
                            
    return 0;
                        }
                    }
                }
                
    return (int)(capacity / 1024 / 1024);
            } 
  • 相关阅读:
    js统一设置富文本中的图片宽度
    springboot 使用Filter
    js判断当前浏览器
    es安装ik后报错无法启动 read write
    logback Filter LevelFilter ThresholdFilter
    使用vue构建一个可视化大数据平台
    常用ES6-ES10知识点总结
    常见的web安全问题总结
    web性能优化指南
    使用node+express+mongodb实现用户注册、登录和验证功能
  • 原文地址:https://www.cnblogs.com/Aricc/p/1524675.html
Copyright © 2011-2022 走看看