在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; }
可以看看.net framework 4.0 Task
thread.start(object obj)
能留个联系方式吗?
@演绎精彩: 多百度吧,线程传参就用上面我说的 调用start启动线程的时候给传入参数
//不带参数调用 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){....}
谢谢各位,我自己已经解决了,用的委托!