如何等待在windows8中完成的所有任务 [英] How to wait for all the tasks done in windows8

查看:111
本文介绍了如何等待在windows8中完成的所有任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有多个任务,我希望在完成所有任务后执行一个方法,该怎么做?比如Task.WhenAll,但我不知道如何使用它。

解决方案

这在文档中有介绍,但这里有一个简单的例子......



任务[] tasks = 任务[ 3 ] 
{
Task.Factory.StartNew(()= > MethodA()) ,
Task.Factory.StartNew(()= > MethodB()),
Task.Factory.StartNew(()= > MethodC())
};

// 阻止所有任务完成。
任务。为WaitAll(任务);


I have multiple tasks in my project, and I want a method executed when all the tasks done, how to do that? like Task.WhenAll, but I don''t know how to use it.

解决方案

This is covered in the documentation, but here is a simple example...

Task[] tasks = new Task[3]
{
    Task.Factory.StartNew(() => MethodA()),
    Task.Factory.StartNew(() => MethodB()),
    Task.Factory.StartNew(() => MethodC())
};

//Block until all tasks complete.
Task.WaitAll(tasks);


这篇关于如何等待在windows8中完成的所有任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆