日期:2014-05-18  浏览次数:20818 次

线程里如何给函数传参和获得返回值?
class ss
{
 ....
 public string aa(string s,int i)
 {
  .....
 }
}

主线程里:
ss s=new ss();
Thread t=new Thread(new ThreadStart(s.aa));

问下怎样在线程中给s里的aa函数传参和获得返回值?最好多给几种方法,多多益善,多谢!

------解决方案--------------------

class ss
{
 ....
 public string _t;
 public int _i
 

 public void bb()
 {
aa(_t,_i)
 }
 public string aa(string s,int i)
 {
.....
 }
}

主线程里:
ss s=new ss();
s._t="tt";
s._i=12
Thread t=new Thread(new ThreadStart(bb));
t.IsBackground=true;
t.Start();
------解决方案--------------------
public void ThreadMethod(Action<string> callback)