nsthread

Stop NSThread on iOS

眉间皱痕 提交于 2019-12-12 02:27:06
问题 I have function call loop, but I want call it if my view appears, and not call it when the view disappears. Loop Function : -(void)updateArray { while (1) { NSLog(@"IN LOOP"); [NSThread sleepForTimeInterval:2.0]; if([FileSizeArray count] >0 || [FileCurrentSizeArray count] >0) { [FileSizeArray removeObjectsInRange:NSMakeRange(1, FileSizeArray.count-1)]; [FileCurrentSizeArray removeObjectsInRange:NSMakeRange(1, FileSizeArray.count-1)]; } [FileNameArray removeAllObjects]; [UserNameArray

Can i call a NSThread function detachNewThreadSelector: toTarget: withObject: with 2 parameters?

折月煮酒 提交于 2019-12-12 01:15:23
问题 I want call a function which makes my main thread stuck using the above function so that it can run in a diff thread. But the problem is that my function have 2 parameters. Is it possible to do so? 回答1: Simply pass as the object an NSDictionary built using all of the arguments needed by your function (can be even more than two using the dictionary). In the code related to the function you pass as a selector, you then retrieve from the dictionary your arguments as the objects stored within the

Load Large Data from multiple tables in parallel using multithreading

人走茶凉 提交于 2019-12-12 00:05:23
问题 I'm trying load data about 10K records from 6 different tables from my Ultralite DB. I have created different functions for 6 different tables. I have tried to load these in parallel using NSInvokeOperations, NSOperations, GCD, Subclassing NSOperation but nothing is working out. Actually, loading 10K from 1 table takes 4 Sec, and from another 5 Sec, if i keep these 2 in queue it is taking 9 secs. This means my code is not running in parallel. How to improve performance problem? 回答1: There may

NSTimer, Threads. How to create a threaded NSTimer?

邮差的信 提交于 2019-12-11 23:09:22
问题 I'm developing a UIView where there must be a process that accesses to remote database and must update a UITableView with the retrieved results. To do that I'm planning use a NSTimer that runs each 10 seconds the update process where database is accessed and data retrieved. The problem is that if I run this in the main thread the view will be frozen till the data is retrieved and loaded. Anyone knows wicht is the best way to do that? Any example will be apreciated. Thanks. EDIT ---- This is

NSRunLoop is receiving a strange selector; possible race condition tomfoolery?

孤街醉人 提交于 2019-12-11 20:55:50
问题 I've got some threads doing heavy work while my main thread handles the UI stuff. The threads callback to the main thread at times to update a progress bar. All in all, it's not that stable. I've fixed problems relating to the logic, but one in particular persists. I've got some code that acts like a stop button, meaning that the thread won't try and renew itself the next time it comes around to check what's going on. Sometimes, when I press the stop button, I receive this error: -[NSRunLoop

How to create thread to checking time?

眉间皱痕 提交于 2019-12-11 19:11:32
问题 I have to setting a time to check for update data from server 2times a day, suppose 9AM and 9PM, but i don't know the way to do that. Create a thread, run every-time and check time current time with setting,if they are equal,so do task? This way is good? I think that's bad performance. 回答1: Use thread but instead of checking every sec, if it is equal. You could use NSNotification. When the time is the same, it will send a notification to get the data. You can read this: iOS timed background

How to Pass a parameter to a method from NSTread?

空扰寡人 提交于 2019-12-11 18:00:01
问题 i am getting a string as parameter in an NSTread now i have to pass this string to next method so how can i do it? my code is given below: calling method and passing an object [self friendPic:user.userId]; my NSTread is this -(void)friendPic:(NSString *)friendID{ NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(getFriendPic) object:friendID]; [thread start]; [thread release]; } -(void)getFriendPic:(NSString *)_friendID{ NSAutoreleasePool *pool = [[NSAutoreleasePool

UIActivityIndicatorView does not show/start animating

自古美人都是妖i 提交于 2019-12-11 17:50:10
问题 I have a view controller with an UIActivityIndicatorView, and a button which triggers synchronisation. Synchronisation is performed in a separate class, usually in the background. The synchronisation can be triggered from different parts of my app, and my view controller is notified of the synchronisation events. Now, when I click the button, the UIActivityIndicatorView does not become visible nor animated. Here is my code in viewDiDLoad: self.syncNowActivityIndicatorView.hidesWhenStopped =

Thread Vs Async call

半世苍凉 提交于 2019-12-11 15:25:30
问题 I wanted to know the best between Spawning a Thread or making a async call using NSURLConnection class. 回答1: See the documentation. An NSURLConnection object provides support to perform the loading of a URL request. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request. i.e. NSURLConnection only supports asynchronous loading of content. Even the sendSynchronousRequest:returningResponse:error: method is really just a

initialize & start NSThread with target & selector

空扰寡人 提交于 2019-12-11 06:29:16
问题 I have a function which takes a block as parameter: typedef void (^ MyCallBack)(int); -(void)doTask:(MyCallBack)callback{ ... } I need to run the function in another thread with NSThread : NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(doTask:) object:nil]; //how to pass callback block here? [myThread start]; But how can I have the callback passed in the NSThread initialisation function above? Is it possible? (If it is impossible, what could be the good