user3587674
user3587674

Reputation: 47

Freezes screen with dispatch

I use this code and it freezes screen. Why this happens?

__block double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

    if ([self loginTypeIsUser])
    {
        [self getVideoPlayLinksForEntity:wallpostEntity];
    }
}); 

Upvotes: 0

Views: 109

Answers (1)

neowinston
neowinston

Reputation: 7764

It happens because you're locking the main thread. You should not dispatch_get_main_queue() but do it on the background.

Try:

dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)

or

dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)

Upvotes: 1

Related Questions