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

C#线程怎么调用带有参数和返回值的方法,在线等~~~
在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;
        }