怎么用新线程调用方法,因为单线程窗体显示时,取cpu序号要等半分钟才能出来。

wufayou433024 2010-10-16 08:45:56
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序号
}
...全文
120 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wufayou433024 2010-10-16
  • 打赏
  • 举报
回复
试过,可以用了。谢谢。
ZengHD 2010-10-16
  • 打赏
  • 举报
回复
        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();
}

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧