日期:2014-05-20  浏览次数:20813 次

怎样 用线程执行方法并返回该方法的返回值。?
怎样 用线程执行方法并返回该方法的返回值。?

------解决方案--------------------
探讨
别沉了。。

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

你得通过别的途径,比如 用类成员来当作返回值
线程函数void返回值的吧

你可以这样
class Worker
{
public:
void ThreadFunc()
{
nReturnValue=xx;
}
public:
int nReturnValue;
}

int CallThreadFunc()
{
Worker w;
threadDelegate = new ThreadStart(w.ThreadFunc);
newThread = new Thread(threadDelegate);
newThread.Start();

return w.nReturnValue;
}

就这个意思

------解决方案--------------------
BackgroundWorker 比较简单
------解决方案--------------------
给线程传入参数并返回结果
http://blog.csdn.net/luminji/archive/2009/03/14/3990729.aspx