nsrunloop

Main Thread Runloop gets blocked on opening nsmenu

房东的猫 提交于 2019-12-01 23:46:59
I have an application for which the UI element includes an NSStatusItem and a menu. Inside my application , I am using NSTask asynchronously to perform some operation and I am using the output obtained using the NSFileHandleReadCompletionNotification to update the menu. But now whenever I click and open the menu , the main runloop goes into NSEventTrackingRunLoopMode and the notification posting fails. So basically with my menu open , no operation takes place on the main thread. Now I found a similar problem on this post but the accepted solution there does not seem to help. I understand that

how to get a accurate timer in ios

感情迁移 提交于 2019-12-01 13:09:33
I am doing an app which needs a timer. I have tried NSTimer but NSTimer always loses or gets delayed. Is there a class in the iOS SDK which can log time accurately. An accuracy between 20ms and 40ms is okay. I'd like to be able to change an image in a fixed time interval. NSTimer *timer1 = [NSTimer scheduledTimerWithTimeInterval:.04f target:self selector:@selector(timer1) userInfo:nil repeats:YES]; - (void)timer1 { NSLog(@"timer1 timer %@",[NSDate date]); } NSTimer is not a high-resolution timer. From the NSTimer class documentation: Because of the various input sources a typical run loop

how to get a accurate timer in ios

这一生的挚爱 提交于 2019-12-01 11:10:38
问题 I am doing an app which needs a timer. I have tried NSTimer but NSTimer always loses or gets delayed. Is there a class in the iOS SDK which can log time accurately. An accuracy between 20ms and 40ms is okay. I'd like to be able to change an image in a fixed time interval. NSTimer *timer1 = [NSTimer scheduledTimerWithTimeInterval:.04f target:self selector:@selector(timer1) userInfo:nil repeats:YES]; - (void)timer1 { NSLog(@"timer1 timer %@",[NSDate date]); } 回答1: NSTimer is not a high

Async NSURLConnection, Concurrent NSOperation, when to use NSRunLoop?

試著忘記壹切 提交于 2019-12-01 07:39:47
I'm trying to run NSURLConnection async in a secondary thread (target is iOS4), for this I have created a concurrent NSOperation, I think I'm almost there, but am not clear on the following: 1) in iOS4 NSOperationQueue addOperation starts the operation in a new thread, because of the use of GCD, based on Technical Q&A QA1712 , however, my tests (simulator and iPad) show that start() is always called on the main thread, any idea, do I need a check here: if on main thread then spawn a new one? 2) if start was actually called on a secondary thread by addOperation(), then I could start my async

Async NSURLConnection, Concurrent NSOperation, when to use NSRunLoop?

ぃ、小莉子 提交于 2019-12-01 05:24:18
问题 I'm trying to run NSURLConnection async in a secondary thread (target is iOS4), for this I have created a concurrent NSOperation, I think I'm almost there, but am not clear on the following: 1) in iOS4 NSOperationQueue addOperation starts the operation in a new thread, because of the use of GCD, based on Technical Q&A QA1712, however, my tests (simulator and iPad) show that start() is always called on the main thread, any idea, do I need a check here: if on main thread then spawn a new one? 2

Stop an NSRunLoop

时光怂恿深爱的人放手 提交于 2019-12-01 04:02:42
I have a connection in a thread, so I add it to the run loop to get all data: [[NSRunLoop currentRunLoop] run]; [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; But I can't find any way to stop it - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ if([NSRunLoop currentRunLoop]){ [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self]; } [connection cancel]; } How can I stop this loop? You can stop the runloop by Core Fundation API : CFRunLoopStop(CFRunLoopGetCurrent()); 来源: https://stackoverflow.com/questions/16211915/stop-an

iOS, NSURLConnection: Delegate Callbacks on Different Thread?

故事扮演 提交于 2019-11-30 12:17:33
问题 How can I get NSURLConnection to call it's delegate methods from a different thread instead of the main thread. I'm trying to mess around with the scheduleInRunLoop:forMode:but doesn't seem to do what I want. I have to download a large file and it interrupts the main thread so frequently that some rendering that is happening starts getting choppy. NSURLRequest * request = [NSURLRequest requestWithURL:url]; NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request

Keep NSThread alive and run NSRunLoop on it

老子叫甜甜 提交于 2019-11-30 06:27:24
问题 So I'm starting a new NSThread that I want to be able to use later by calling performSelector:onThread:... . From how I understand it calling that methods add that call to the runloop on that thread, so on its next iteration it will pop all these calls and subsequently call them until there is nothing left to call. So I need this kind of functionality, an idle thread ready for work that I just can call upon it. My current code looks like this: - (void)doInitialize { mThread = [[NSThread alloc

NSTimer requiring me to add it to a runloop

ぐ巨炮叔叔 提交于 2019-11-30 03:15:20
I am wondering if someone can explain why dispatching back to the main queue and creating a repeating NSTimer I am having to add it to RUN LOOP for it too fire? Even when using performselectorOnMainThread I still have to add it to a RUN LOOP to get it to fire. Below is an example of my question: #define queue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) #define mainqueue dispatch_get_main_queue() - (void)someMethodBeginCalled { dispatch_async(queue, ^{ int x = 0; dispatch_async(mainqueue, ^(void){ if([_delegate respondsToSelector:@selector(complete:)]) [_delegate complete:nil]

“Block” main thread (dispatch_get_main_queue()) and (or not) run currentRunLoop periodically - what is the difference?

帅比萌擦擦* 提交于 2019-11-29 16:02:50
问题 I have the following code: - (void)test_with_running_runLoop { dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); NSTimeInterval checkEveryInterval = 0.05; NSLog(@"Is main queue? : %d", dispatch_get_current_queue() == dispatch_get_main_queue()); dispatch_async(dispatch_get_main_queue(), ^{ sleep(1); NSLog(@"I will reach here, because currentRunLoop is run"); dispatch_semaphore_signal(semaphore); }); while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) [[NSRunLoop