C# C相当于Objective-C';s调度组和队列?
我正在将Objective-C应用程序移植到C#,我正在努力在C中实现以下功能#C# C相当于Objective-C';s调度组和队列?,c#,objective-c,multithreading,C#,Objective C,Multithreading,我正在将Objective-C应用程序移植到C#,我正在努力在C中实现以下功能# 我该怎么做呢?注意:这至少需要.NET Framework的4.5版 // create a new dispatch group List<Task> tasks = new List<Task>(); // iterate over a collection adding tasks to the dispatch group for (…) { Task task = Tas
我该怎么做呢?注意:这至少需要.NET Framework的4.5版
// create a new dispatch group
List<Task> tasks = new List<Task>();
// iterate over a collection adding tasks to the dispatch group
for (…) {
Task task = Task.Run(() => {
// do stuff
});
tasks.Add(task);
}
// wait for them all to finish
Task.WaitAll(tasks.ToArray());
// do more stuff that depends on them all finishing
//创建新的调度组
列表任务=新列表();
//迭代集合,将任务添加到调度组
对于(…){
任务=任务。运行(()=>{
//做事
});
任务。添加(任务);
}
//等待他们全部完成
Task.WaitAll(tasks.ToArray());
//做更多的事情,这取决于他们所有的完成
请参见C#。谢谢!正是我想要的
// create a new dispatch group
List<Task> tasks = new List<Task>();
// iterate over a collection adding tasks to the dispatch group
for (…) {
Task task = Task.Run(() => {
// do stuff
});
tasks.Add(task);
}
// wait for them all to finish
Task.WaitAll(tasks.ToArray());
// do more stuff that depends on them all finishing