如何检查dispatch_async块已经完成运行 [英] how to check an dispatch_async block has finished running

查看:188
本文介绍了如何检查dispatch_async块已经完成运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我需要能够在块运行完成后运行segue。我有一个块做一些JSON的东西,我需要知道什么时候运行完毕。

So basically I need to be able to run a segue after a block has finished running. I have a block which does some JSON stuff and I need to know when that has finished running.

我有一个名为json_queue的队列。

I have a queue which I have called json_queue.

jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL);

然后我有一个带有以下语法的dispatch_async块:

I then have a dispatch_async block with this syntax:

  dispatch_async(jsonQueue, ^{
  [self doSomeJSON];
  [self performSegueWithIdentifier:@"modaltomenu" sender:self];
  });

它不会让我执行该行:[self performSegueWithIdentifier:@modaltomenusender:self] ;

It wont let me perform the line: "[self performSegueWithIdentifier:@"modaltomenu" sender:self];"

试图从主线程或网络线程以外的线程获取Web锁。这可能是从辅助线程调用UIKit的结果。现在崩溃...

Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

我在哪里可以检查线程何时完成其脏工作以便我可以调用segue?

Where can I check to find out when the thread has done its dirty work so i can call the segue?

谢谢你们可爱的人们。

PS:对任何可以提供帮助的人来说,啤酒和ups以及泰迪熊和鲜花3。

PS: beer and ups and teddy bears and flowers to whoever can help <3.

推荐答案

您应该只在主线程上调用UI方法。尝试在主队列上调度performSegueWithIdentifier:

You should call UI methods on main thread only. Try to dispatch performSegueWithIdentifier: on main queue:

dispatch_async(jsonQueue, ^{
    [self doSomeJSON];
    dispatch_sync(dispatch_get_main_queue(), ^{
        [self performSegueWithIdentifier:@"modaltomenu" sender:self];
    });
});

这篇关于如何检查dispatch_async块已经完成运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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