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
2
votes
2 answers

calling method from NSThread

I am trying to call a class method in my application: didFinishLaunchingWithOptions: using NSThread. But strangely this method is not getting called. I have tried the below in didFinishLaunchingWithOptions method. [self…
2
votes
2 answers

How can I cancel performSelectorOnMainThread?

How can I cancel performSelectorOnMainThread? I have this code: myClass = [[MyClass alloc] init]; [myClass performSelectorOnMainThread:@selector(setupPlayer) withObject:nil waitUntilDone:YES];
neowinston
  • 7,584
  • 10
  • 52
  • 83
1
vote
1 answer

increase a value while uibutton is kept pressing in iphone

I am trying to increase a variable's value while uibutton is kept pressing. But when user leaves button, increasing of variable's value will be stopped. i have tried using threads with touch down and touchupinside but couldn't make it work. -(void)…
gurkan
  • 3,457
  • 4
  • 25
  • 38
1
vote
0 answers

How to run, restart and kill thread in Objective C?

I have a function which update pagination i.e. calculate total number of pages. - (void) updatePagination{ if(!paginating){ NSLog(@"Pagination Started!"); paginating = YES; totalPagesCount=0; …
Soniya
  • 600
  • 7
  • 34
1
vote
0 answers

Is that possible I can use the CFRunloop mechanism within a threadFunction created by pthread?

For some reason, I cannot use NSThread. But I thing the communication way using the CFRunloopSource between 2 threads is convient. So I wonder that if I can obtain the current cfrunloop ref within the thread context created by pthread? I grabbed…
1
vote
2 answers

variable set & Get, Race condition

I am setting a variable in a thread, and I'm checking using it for a condition in another thread. I'm aware of the race condition here. But not sure if doing the set in atomic way will be enough. Can you please let me know how to solve this in…
coder000001
  • 476
  • 4
  • 22
1
vote
2 answers

Objective-C: What boilerplate code do you need for NSThread?

I find the documentation on NSThread not very informative for newcomers in NSThread and i don't see any "this is THE boilerplate code" provided that contains all the code for NSThread with NSRunLoop. A lot of code pieces are scattered through the…
Tomen
  • 4,854
  • 5
  • 28
  • 39
1
vote
1 answer

Using NSTimer to start NSThread in ios

I need a background operation to be scheduled every 10 minutes or so. The operation consists of gather objects from core data and uploading their information to a webservice not to change them in any way. The approach I am thinking of is to create a…
Bjarke
  • 1,283
  • 11
  • 36
1
vote
3 answers

performSelector with time delay does not work in for loop - iPhone

I was hoping someone could help me out. I am writing a simple game, when a user pushes a button an array of numbers corresponding to button numbers is generated then a for loop is used to turn each button on and off in sequence with a time delay.…
user961632
  • 39
  • 8
1
vote
0 answers

Stop NSThread execution when application will be sent in background mode

I have the following problem in my iphone application: I have a NSThread who works with a TCP socket. When this thread is performing a very long function, I send in the background mode the application. When I return from this background thread…
Safari
  • 11,437
  • 24
  • 91
  • 191
1
vote
1 answer

How is a thread related to its NSAutorelease pool?

I have a general idea on how NSAutorelease pool works. we have objects in it which are autoreleased and when the drain method is called. the pool is checked for objects with retaincount as +1, and are thus deallocated. but what I am not sure of…
Amogh Talpallikar
  • 12,084
  • 13
  • 79
  • 135
1
vote
1 answer

NSInputStream in background thread doesn't call NSStreamEventHasBytesAvailable

I am working on streaming part of application. I needed to put streaming process on the background thread that it uses NSinputstream and NSOutputstream . then I send http commands over this streaming channel on the same thread. I receive the…
1
vote
5 answers

retrieving image from image url

how to get uiimage from a nsurl other than using the method NSData *data = [NSData dataWithContentsOfURL:url]; There is another problem the ui elements are not working while a nsthread is running
iOS Developer
  • 1,723
  • 2
  • 16
  • 47
1
vote
1 answer

Background thread running for fetching image from Facebook album

- (void)request:(FBRequest *)request didLoad:(id)result { // NSArray *resultData = [result objectForKey:@"data"]; NSMutableArray *photos = [[NSMutableArray alloc] initWithCapacity:1]; // imageArray = [[NSMutableArray…
Meera
  • 77
  • 6
1
vote
0 answers

Thread crash, which one is it?

My app crashes when it switches threads. Could not see which one is crashing? Anyone can see it from these details? Please let me know if you have any suggestions. I tried to find the thread based on the hex 0x207, but there is no such thread. …
Zsolt
  • 3,648
  • 3
  • 32
  • 47