nsthread

NSOperation - Forcing an operation to wait others dynamically

拜拜、爱过 提交于 2019-11-28 16:33:13
I am trying to implement an operation queue and I have the following scenario: NSOperation A NSOperation B NSOperation C NSOperation D NSOperationQueue queue I start adding A to queue . During the execution of A I need to get some data from B and I can't continue with A until B returns what I need. The same situation will occur for B depending on C and for C depending on D . To manage this, at each NSOperation I have this code: NSOperation *operation; //This can be A, B, C, D or any other NSOperation [self setQueuePriority:NSOperationQueuePriorityVeryLow]; //Set the current NSOperation with

does NSThread create autoreleasepool automatically now?

ⅰ亾dé卋堺 提交于 2019-11-28 08:43:04
I have test code like this - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void)test { MyClass *my = [[[MyClass alloc] init] autorelease]; NSLog(@"%@",[my description]); } I did not create any autoreleasepool for my own thread, but when the thread exit, object "my" just dealloc.why? even though I change my test code as below - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void

applicationDidEnterBackground and applicationWillEnterForeground method are not called when pressed home button in iOS simulator

这一生的挚爱 提交于 2019-11-28 05:32:15
问题 I need a long running task to be done in background as well as in foreground. This updates the core data. So to maintain UI responsive I created an another thread where I use different managedObjectContext(MOC). So a timer is set in background as well as in foreground and is inactivated appropriately when state changes. Before the task is starting and after the task is completed when I press home button it calls the two delegate methods properly but during the task is active when I press home

Perform UI Changes on main thread using dispatch_async or performSelectorOnMainThread? [duplicate]

。_饼干妹妹 提交于 2019-11-28 05:31:29
Possible Duplicate: Grand Central Dispatch (GCD) vs. performSelector - need a better explanation To execute "stuff" on the main thread, should I use dispatch_async or performSelectorOnMainThread ? Is there a preferred way, right/or wrong, and/or best practice? Example: I'm performing some logic within the block of an NSURLConnection sendAsynchronousRequest:urlRequest method. Because I'm doing stuff to the main view such as presenting a UIAlertView I need to show the UIAlertView on the main thread. To do this I'm using the following code. [NSURLConnection sendAsynchronousRequest:urlRequest

GCD vs performSelectorInBackground/performSelectorOnMainThread

僤鯓⒐⒋嵵緔 提交于 2019-11-28 05:01:33
I am new in ios development. I have following questions: When we use GCD(dispatch_group_async, dispatch_async(dispatch_get_main_queue()...) and when we use performSelectorInBackground/performSelectorOnMainThread? What's the differences between those two. I know when we use performSelectorInBackground, we create a new NSThread. But isn't the same when we use dispatch_group_async? Because if we create more than one dispatch_group_async, it means we need to submit more than one blocks in queue. And those blocks might run on different queues. Therefore, when we create more than one dispatch_group

setKeepAliveTimeout and BackgroundTasks

懵懂的女人 提交于 2019-11-28 04:36:01
I've a big headache with the topic. I'm working on an application that needs to poll a webserver regularly, in order to check for new data. Based on the returned information, I wish to push a local notification to the user. I know that this approach is slightly different from the one depicted by Apple, in which a remote server makes the work, pushing a remote notification, based on APNS. However, there are many reasons for which i cannot take this approach in consideration. One for all, is the user authentication mechanism. The remote server, for security reasons, cannot take into account the

NSThreads in Automatic Reference Counting(ARC)

丶灬走出姿态 提交于 2019-11-28 03:45:37
问题 i am trying to use NSThreads with ARC in 4.3.5. With iOS 5 everything works perfect, but if i try it on a older iOS like 4.3 its leaking. Normally i would use a Autoreleasepool for NSThreads but since there is no manual Autoreleasepool in ARC i don't know how to fix this. I get loads of Messages like "__NSAutoreleaseNoPool(): Object 0x4567b40 of class NSComparisonPredicate autoreleased with no pool in place - just leaking" in my Console after i start a Thread. NSThread detachNewThreadSelector

How to exit NSThread

依然范特西╮ 提交于 2019-11-28 01:38:45
问题 I am using a thread like this, [NSThread detachNewThreadSelector:@selector(myfunction) toTarget:self withObject the thread is running correctly, I want to quit the thread in the middle,how can I do this.If I use [NSThread exit] the application is hanging. 回答1: In which thread are you running "[NSThread exit]"? [NSThread exit] runs in the current thread so you need to call this as part of the myfunction selector. If you call it in the main thread, it will just exit the main thread. Also, it's

Does every thread need its own autorelease pool?

荒凉一梦 提交于 2019-11-27 22:47:24
问题 Does every thread have to have its own pool? I am writing an iPhone app which uses threads. If I do not put a pool on a thread it complains abut leaking. What I wanted to do was to store some object which outlives the thread. How can I do it? 回答1: No, every NSThread has its own NSRunLoop , but not its own NSAutoreleasePool . Thus you have to create one and if you are performing a large operation or a operation that needs a lot of time, you really should drain the pool from time to time to

Is it ok to create a UIView on a background thread?

人走茶凉 提交于 2019-11-27 22:04:45
I know UIView are not thread safe so i cant add a view on a background thread, to work around this is it ok to create a UIView on a background thread then add it on the main thread? Note: the reason im not doing this on the main thread is because my actual code is a lot more complex and therefor takes a while to create all the views and fill the values. I dont want the UI to become un-responsive when I do this so im trying to work around this. for example.. -(void)addLabel//called on background thread { UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0,0,40,100)]; [label setText:@