About running thread in background

Hi everyone,
I’m newbie in cocos2dx dev,i have a question about running thread in background, i have searched alot but i found nothing about it in cocos2dx.
I make a game have socket comunication with server (using libcurl), and make it work on a thread (i’m using pthread to make multithread). when device go to background mode , this thread was sleep too :frowning:
In cocos2d-iphone i can use code below to keep it working in backgorund mode

UIApplication *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
        [app endBackgroundTask:bgTask]; 
        bgTask = UIBackgroundTaskInvalid;

Any suggestion for me? thanks so much and sorry for my bad English :smiley:

On AppDelegate.cpp, you will find AppDelegate::applicationDidEnterBackground* andAppDelegate::applicationWillenterForeground(). You will seeCCDirector::sharedDirector() > pause* and *CCDirector::sharedDirector> resume()*, respectively. If you comment those two lines, CCDirector would keep running even on background.

That being safe or not, I do not know.

1 Like

its not work for me