c# - 如何捕获线程执行中方法返回的值#

标签 c# multithreading

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/

相关文章:

iphone - 在 iOS 中创建一个连续的后台线程

java - 为什么在线程调用启动时不调用定义的 run() 方法?

c# - ASP.NET 将所有文件下载为 Zip

c# - 在不同线程中处理列表项

c# - 如何在 GridView 中创建删除按钮?

C# HttpListener 和 Windows 防火墙

android - Sqlite死锁问题

Java 多线程矩阵乘法

Python线程错误,有人有解决方案吗?

c# - 在 Windows Phone 8 中获取 UI 调度程序