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; }
梦里花落0921
浏览 941回答 6
6回答

12345678_0001

可以看看.net framework 4.0 Task

翻翻过去那场雪

thread.start(object obj)

慕娘9325324

@演绎精彩: 多百度吧,线程传参就用上面我说的 调用start启动线程的时候给传入参数

ABOUTYOU

//不带参数调用 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){....}

ibeautiful

谢谢各位,我自己已经解决了,用的委托!
打开App,查看更多内容
随时随地看视频慕课网APP