在windouws服务中需要线程同时调用三个方法,我现在只贴了一个,因为三个方法的参数和返回值都是一样的,请问下大家用线程怎么调用啊,最好贴下源码。谢谢! public AddTest GetCpu(string ip)
{
SimpleSnmp snmp = new SimpleSnmp(ip, "WWW");
AddTest test = new AddTest();
if (!snmp.Valid)
{
//this.TextBox1.Text = "SNMP agent host name/ip address is invalid.";
//return;
}
Dictionary<Oid, AsnType> result = snmp.Walk(SnmpVersion.Ver2, "1.3.6.1.2.1.25.3.3.1.2");
if (result == null)
{
//this.TextBox1.Text = "No results received.";
//return;
}
double cupUse = 0;
foreach (KeyValuePair<Oid, AsnType> kvp in result)
{
//this.TextBox1.Text += string.Format("CPU使用率为:{0} {1} {2}", kvp.Key.ToString(),
// SnmpConstants.GetTypeName(kvp.Value.Type),
// kvp.Value.ToString() + "%" + "\r\n");
cupUse += double.Parse(kvp.Value.ToString());
}
cupUse = cupUse / 2;
test.CPU = cupUse;
return test;
}
6 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
//不带参数调用 Thread thread1 = new Thread(new ThreadStart(Method1)); thread.Start(); //带参数调用 Thread thread2 = new Thread(new ParameterizedThreadStart(Method2)); thread.Start(param); ...... public void Method1(){....} public void Method2(object obj){....}
- 6 回答
- 0 关注
- 940 浏览
添加回答
举报
0/150
提交
取消