Thread[] threads = new Thread[12];
int temp;
for (int i = 0; i < threads.Length - 1; i++)
{
temp = i;
threads[temp] = new Thread(new ThreadStart(()=> test(test1[temp],"start", temp)));
threads[temp].Start();
//threads[temp].Join();
}
for(int i=0; i<threads.Length-1; i++)
{
threads[i].Join();
}
//需要捕获线程中执行“test1”方法返回的响应。
最佳答案
您可以使用 Task<T>
(如果您使用的是 .NET 4+),它有一个返回值。您还可以使用事件在线程完成其操作时收到通知,并以这种方式获取返回值。
关于c# - 如何捕获线程执行中方法返回的值#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32679181/