Q:

How to run two tasks independently

I am building one application on Mac OS X (10.6).  In this application, I have one screen where user will provide input and that will be saved as a plist in local folder.  This plist file needs to be trasferred to server using HTTP POST service.  There should be check for server connectivity and if connections fails the files will be saved in local folder.  With certain time duration, again the server connection will be checked and if found, then send all the files store in local folder one by one. 
Basically, The GUI application will run continously to get input from user and in another thread there should be check for server connectivity and sending the files. 
So my question is what might be the good approach to solve the problem and if any one can send some sample code, it would be great to me. 
Thanks,
Barun 

A:

There are several approaches to threading in Objective-C!  The easiest strategy is NSOperationQueue.  Override NSOperation to handle your HTTP request, optionally set a completion block if you need to be notified when it's done, add an instance of it to an NSOperationQueue object and you're good to go.  Set up an NSTimer to reschedule the upload if it fails the first time.  You can use NSURLConnection to handle the web stuff.  Note that NSURLConnection can make connections asynchronously or blocking.  Since your NSOperation subclass runs in a separate thread already, you probably want to use the blocking method (if you don't you have to create a concurrent NSOperation subclass, which is a lot more work). 
You can also use Grand Central Dispatch's API, detach a new thread to methods you specify, or use plain old c (I wouldn't recommend the last two but it's good to mention them).  As a bonus, NSOperationQueue and Grand Central Dispatch both know "what's right" when you have multiple operations running at once, and will scale the number of threads to fit the number of core's in the user's computer to obtain the best performance. 
Check the docs for NSOperationQueue, NSOperation, and NSURLConnection.  The guides and example projects will have all the source code you need to get you started in the right direction.