小编mha*_*nne的帖子

如何获取任务的结果或返回值?

有人可以向我解释如何返回任务的结果吗?我目前正在尝试执行以下操作,但我的任务不会返回我期望的列表吗?这里有什么问题?

static void Main()
{
    List<Task> tasks = new List<Task>();
    List<string> sha256_hashes = new List<string>();
    List<string> results = new List<string>();

    sha256_hashes.Add("hash00");
    sha256_hashes.Add("hash01");
    sha256_hashes.Add("hash03");
    foreach(string sha256 in sha256_hashes)
    {
        string _sha256 = sha256;
        var task = Task.Factory.StartNew(() => GetAdditionalInfo(_sha256));
        tasks.Add(task);
    }
    Task.WaitAll(tasks.ToArray());
   //I want to put all the results of each task from tasks but the problem is
   //I can't use the Result method from the _task because Result method is not available
   //below is my plan to get all the …
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

task-parallel-library ×1