我怎么知道我在Grand Central Dispatch中完成的所有任务?

编程入门 行业动态 更新时间:2024-10-27 00:28:25
本文介绍了我怎么知道我在Grand Central Dispatch中完成的所有任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要将多个任务发送到Grand Central Dispatch才能运行.有些任务将首先完成,而有些任务将最后完成.

I need to send multiple tasks to Grand Central Dispatch to run. Some tasks will finish first, while some will finish last.

我怎么知道我在Grand Central Dispatch中完成的所有任务?

How do I know all my tasks in Grand Central Dispatch finished?

我应该使用计数器记录完成的任务数吗?还有更聪明的方法吗?

Should I use a counter to record the number of tasks finished? Any smarter method?

推荐答案

您可以使用调度组在所有任务完成时得到通知.这是来自 cocoasamurai的示例. blogspot/2009/09/guide-to-blocks-grand-central-dispatch.html

You can use dispatch groups to be notified when all tasks completed. This is an example from cocoasamurai.blogspot/2009/09/guide-to-blocks-grand-central-dispatch.html

dispatch_queue_t queue = dispatch_get_global_queue(0,0); dispatch_group_t group = dispatch_group_create(); dispatch_group_async(group,queue,^{ NSLog(@"Block 1"); }); dispatch_group_async(group,queue,^{ NSLog(@"Block 2"); }); dispatch_group_notify(group,queue,^{ NSLog(@"Final block is executed last after 1 and 2"); });

更多推荐

我怎么知道我在Grand Central Dispatch中完成的所有任务?

本文发布于:2023-08-02 13:28:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1278188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   我怎么   Grand   Central   Dispatch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!