public string getCpu()
        {
            string strCpu = null;
            ManagementClass myCpu = new ManagementClass("win32_Processor");
            ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
            foreach (ManagementObject myObject in myCpuConnection)
            {
                strCpu = myObject.Properties["Processorid"].Value.ToString();
                break;
            }
            return strCpu;
        } //以下这个方法要怎么写才对呀?
        public viod ckgetCpu()
          {
            string jqm = getCpu();//获得24位Cpu和硬盘序列号            
            if (jqm == "178BFBFF00100F42F4002453")
            {
                cls_gq.gq = "否";
                return true;
            }
            else
            {
                cls_gq.gq = "是";
                return false;            }  
           }
   
        
        private void frm_main_Load(object sender, EventArgs e)
        {
            Thread t = new Thread(new ThreadStart(ckgetCpu); //此处用一个新线程来取得 cpu序号
         }

解决方案 »

  1.   

            public string getCpu()
            {
                string strCpu = null;
                ManagementClass myCpu = new ManagementClass("win32_Processor");
                ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
                foreach (ManagementObject myObject in myCpuConnection)
                {
                    strCpu = myObject.Properties["Processorid"].Value.ToString();
                    break;
                }
                return strCpu;
            }        //以下这个方法要怎么写才对呀?
            public void ckgetCpu()
            {
                string jqm = getCpu();//获得24位Cpu和硬盘序列号  
                if (jqm == "178BFBFF00100F42F4002453")
                {
                    cls_gq.gq = "否";
                }
                else
                {
                    cls_gq.gq = "是";
                }
            }        private void button1_Click(object sender, EventArgs e)
            {
                Thread t = new Thread(new ThreadStart(ckgetCpu)); //此处用一个新线程来取得 cpu序号
                t.Start();
            }