Questions tagged [nsthread]

`NSThread` is part of the Objective-C Foundation Framework and provides developers a way to create and manage threads.

An instance of NSThread controls a thread of execution. Developers can use this class when they would like to perform a series of tasks in its own thread of execution. An example is if the developer wanted to have an Objective-C method run in its own thread of execution.

Threads are useful for long-running tasks that avoid blocking the main thread of the application (where user interface and event-related tasks are handled), as well as dividing a large task into several smaller sub-tasks. This can lead to performance improvements.

In GNUStep, NSThread essentially encapsulates OpenStep threading. Each process starts with a main thread and additonal threads can be created by using NSThread. The GNUStep implementation of OpenStep was designed so that the internals of the base library do not use threading (except in the case of methods that explicitly deal with threads). This makes it possible to write applications without any sort of threading.

References

729 questions
0
votes
3 answers

Is it possible for a delayed call to never get called in a thread?

Say you attach a timer to a runloop in a particular thread but the thread has exited before the timer gets triggered, causing the method to not be executed. Is this scenario possible?
Boon
  • 40,656
  • 60
  • 209
  • 315
0
votes
2 answers

NSThread Programming issues

I am currently learning IOS Threading programming... I encountered an issue: Here comes my code, please kindly have a look: int main(int argc, const char * argv[]) { @autoreleasepool { NSThread *t1 = [[NSThread…
David Dai
  • 1,095
  • 2
  • 8
  • 11
0
votes
3 answers

How to kill NSThread while clicking on new tab iOS?

I building an app has 4 tab (Tabbar Controller), and each tab I call a function (updateArray) after 2s. I want to when click on other tab, updateArray() function is kill. My problem is when on tab, updateArray() call after 2s, when I click on other…
NGOT
  • 149
  • 5
  • 12
0
votes
4 answers

How to stop call loop function in IOS

I want to stop calling loop function when View disapear. How can i do that? This is my code: -(void) viewWillAppear:(BOOL)animated { [self performSelectorInBackground:@selector(updateArray) withObject:nil]; } And : …
0
votes
2 answers

Stop NSThread on iOS

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]; …
0
votes
2 answers

iOS: Stopping a Thread / Method in the Middle of Process

I have a UITextfield and a UIButton. The user can enter, for example, search word such as "dog" or "cat" and it will trigger a method in another class that runs on a custom dispatch GCD queue to fetch the images (around 100 or so). Everything works…
Unheilig
  • 16,196
  • 193
  • 68
  • 98
0
votes
4 answers

Not working with NSThread: performSelector:withObject:afterDelay:?

is it possible that performSelector:withObject:afterDelay: doesn't work in subthreads? I'm still new to objective c and Xcode so maybe I've missed something obvious... :/ I'd really appreciate some help. All I want to do is to show an infolabel for…
Teapot
  • 59
  • 9
0
votes
1 answer

Background fetch on iOS and handling the returned data

I have a DataManager class that is responsible for fetching data and handing it over to the DatabaseManager, which in-turn will insert it into core data. The method that exposes itself to the webservice is below -(void)fetchDetailsForId:(NSString…
iSee
  • 604
  • 1
  • 14
  • 31
0
votes
3 answers

XCode: Stop Animating Activity Indicator after Executing a Method From Another File

Ok, this seems like it should be very simple - All I want to do is call my ServerConnect.m (NSObject), NSURL Connection Request Method, from my SignIn.m (ViewController) and stop the UIActivityIndicatorView after the NSURL Request has completed. Of…
JRoss
  • 177
  • 10
  • 23
0
votes
2 answers

Thread-safe NSMutableArray question

I am developing a RSS reader which uses a NSMutableArray (_stories) to store the contents of the RSS Feed. This array is being used by two different threads in the application and may be accessed simultaneously in two occasions, since: It is the…
Eduardo Coelho
  • 1,953
  • 8
  • 34
  • 60
0
votes
1 answer

Wait for URLConnection block to finish

I'm creating a REST client class for my iPad app. So I created a BOOL method which does the login using an NSURLConnection subclass I created earlier. This JWURLConnection has block type properties for the finishLoading and failWithError…
0
votes
1 answer

NSThread Error in Objective-C

I am getting this error bool _WebTryThreadLock(bool), 0x1b53d0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... what is this…
Biranchi
  • 16,120
  • 23
  • 124
  • 161
0
votes
3 answers

peformSelector with two arguments

I've to run this method on background or in new thread. How to pass two arguments in performSelector? [self addMessageFromRemoteNotification:userInfo updateUI:NO]; -(void)addMessageFromRemoteNotification:(NSDictionary *)userInfo…
dineshsurya
  • 215
  • 1
  • 10
0
votes
0 answers

Copy files from Directory to Directory in iOS Objective-C

In my app I want to copy files from one directory to another directory. In the source directory there are files and folders. I do this in the code below: - (BOOL)copyDirectory:(NSString*)Directory toDirectory:(NSString*)targetDirectory { …
Guy Kahlon
  • 4,510
  • 4
  • 30
  • 41
0
votes
1 answer

sleep block all threads not just one NSthreads

I'm calling sleep() on an NSThread, ( I subclassed NSThread and put a run-loop in it) The thing is that this sleep call is blocking all threads not just my NSThread ... What's the best way to get around this problem?
user1028028
  • 6,323
  • 9
  • 34
  • 59