nsthread

Threaded NSTimer

我是研究僧i 提交于 2019-12-02 04:41:29
I am aware of the many questions regarding this topic, as I myself have asked one previously however, my issue now seems to be more related to the threading part. I have the following 2 methods. -(void) restartTimer { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; self.timer = [NSTimer scheduledTimerWithTimeInterval:1. target:self selector:@selector(dim) userInfo:nil repeats:YES]; time = 31; NSLog(@"calling restart timer"); [self performSelectorOnMainThread:@selector(timerImageUpdate) withObject:nil waitUntilDone:NO]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode

RetainCount OK to use in this instance?

喜欢而已 提交于 2019-12-01 22:21:01
RetainCount == BAD retainCount is taboo, unreliable, unpredictable, and in general shouldn't be used. I don't use it anywhere in my code, but I have seen it in one class that I use in an interesting way. I have a class that runs a thread that runs indefinitely until the thread is cancelled. The catch is that the thread increases the retain count of the owner, in my case the class that instantiated it. So, even if I am done using that class, that instance is still going to hang around unless whoever is managing my class also has the smarts to know to shut down the thread. That is one solution,

core data update in background

♀尐吖头ヾ 提交于 2019-12-01 14:27:18
I need to basically update my core data in a background thread without blocking UI and save it. After saving should reload table View to view the changes. So for doing this I thought of using dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // Add code here to do background processing NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; self.backgroundManagedObjectContext = context; if(self.managedObjectContext == nil) self.managedObjectContext = [(AppDelegate *)[[UIApplication

Pausing an NSTimer

拈花ヽ惹草 提交于 2019-12-01 12:31:59
I have a UIView with a UITableView and a UIImageView in it. The UITableView takes up the top half of the UIView . The UIImageView takes the bottom half of the UIView . I am using an NSTimer to update the image that is being displayed in the UIImageView . Basically, every 3 seconds, the UIImageView loads in a new UIImage . Problem is, if I select a row from the UITableView , the NSTimer keeps running. How can I stop the NSTimer on didSelectRowFromIndexPath , and then start it again when the view returns to the screen? -(void)viewDidLoad { NSThread* timerThread = [[NSThread alloc] initWithTarget

Pausing an NSTimer

半世苍凉 提交于 2019-12-01 11:18:36
问题 I have a UIView with a UITableView and a UIImageView in it. The UITableView takes up the top half of the UIView . The UIImageView takes the bottom half of the UIView . I am using an NSTimer to update the image that is being displayed in the UIImageView . Basically, every 3 seconds, the UIImageView loads in a new UIImage . Problem is, if I select a row from the UITableView , the NSTimer keeps running. How can I stop the NSTimer on didSelectRowFromIndexPath , and then start it again when the

Coredata performBlock then return the new value

不羁的心 提交于 2019-12-01 11:09:17
How to return the new object saved in coredata if I am using performBlock to save a managedObjectContext? The requirement is, add an entry in coredata, and return it. My code is something like this: //create a privateMOC NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; //set parentContext [private setParentContext:self.coredataManager.managedObjectContext]; __block Detail *object = nil; [private performBlock:^{ //fetch from the db object = [self.coredataManager insertObjectWithEntityName:NSStringFromClass([Detail class])]

why do I get “wait_fences: failed to receive reply” for this code?

[亡魂溺海] 提交于 2019-12-01 11:05:10
why do I get "wait_fences: failed to receive reply" for this code? Is it the way I'm using notification to communicate back to the main thread? #import "ViewController.h" @implementation ViewController @synthesize alert; #pragma mark - Background Thread Test Methods - (void) ConfigTasksForBackground:(id)sender{ NSLog(@"ConfigTasksForBackground - Starting"); [NSThread sleepForTimeInterval:6]; [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object:self]; NSLog(@"ConfigTasksForBackground - Ending"); } #pragma mark - Callbacks - (void) ModelChangedHandler:(NSNotification

Coredata performBlock then return the new value

天涯浪子 提交于 2019-12-01 08:16:10
问题 How to return the new object saved in coredata if I am using performBlock to save a managedObjectContext? The requirement is, add an entry in coredata, and return it. My code is something like this: //create a privateMOC NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; //set parentContext [private setParentContext:self.coredataManager.managedObjectContext]; __block Detail *object = nil; [private performBlock:^{ //fetch

How a runloop actually works

折月煮酒 提交于 2019-12-01 04:03:49
问题 Earlier this month I asked this question 'What is a runloop?' After reading the answers and did some tries I got it to work, but still I do not understand it completely. If a runloop is just an loop that is associated with an thread and it don't spawn another thread behind the scenes how can any of the other code in my thread(mainthread to keep it simple) execute without getting "blocked"/not run because it somewhere make an infinite loop? That was question number one. Then over to my second.

how to stop nsthread

你离开我真会死。 提交于 2019-12-01 00:43:52
I am using a thread to update messages in background in my application. The thread is started in my messages class. Messages.m timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread:) object:nil]; [timerThread start]; now I want the thread to stop when the user signout of the application. For that in the signout method (in another class) I added Messages *msg=[[Messages alloc]init]; [msg.timerThread cancel]; [msg release]; But even after signing out of the application the thread is still running. ( I am assuming here that you create an instance of Messages