Dispatch_group_async can be used to listen to whether a group of tasks are completed and be notified to perform other operations when completed. This method is useful, for example, you perform three download tasks, and when three tasks are downloaded, you are notified that the interface is complete. Here is an example code:
- dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default, 0);
- dispatch_group_t group = Dispatch_group_create ();
- Dispatch_group_async (group, queue, ^{
- [Nsthread sleepfortimeinterval:1];
- NSLog (@ "group1");
- });
- Dispatch_group_async (group, queue, ^{
- [Nsthread Sleepfortimeinterval:2];
- NSLog (@ "group2");
- });
- Dispatch_group_async (group, queue, ^{
- [Nsthread Sleepfortimeinterval:3];
- NSLog (@ "Group3");
- });
- Dispatch_group_notify (Group, Dispatch_get_main_queue (), ^{
- NSLog (@ "UpdateUi");
- });
- Dispatch_release (group);
The Didatch_group_async method uses