日期:2014-05-17  浏览次数:20635 次

资源释放

是用
moc = null;
mc = null;


还是用
moc.Dispose();
mc.Dispose();



        /// <summary>
        /// 获取网卡信息
        /// </summary>
        /// <returns></returns>
        public static List<string> GetMacAddress()
        {
            try
            {
                //获取网卡硬件地址 
                string mac = "";
                List<string> macList = new List<string>();
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    if ((bool)mo["IPEnabled"] == true)
                    {
                        mac = mo["MacAddress"].ToString();
                        macList.Add(mac);
                    }
                }
                moc = null;
                mc = null;
                return macList;