On Jun 24, 2009, at 1:49 AM, Chris(吴潮江) wrote:

On Jun 24, 2009, at 2:28 AM, Ken Thomases wrote:

You probably don't need to use a background thread to do FTP. You can do it using asynchronous methods on the main thread. Since you can, you probably should. It's almost always less error prone and even more efficient.

Considering the GUI operations, I use the background thread to do FTP.

But using _asynchronous_ methods for the FTP won't interfere with GUI operations.

There are several asynchronous APIs you could use. You could use NSURLConnection and the related classes (see the URL Loading System documentation). You can use NSStream, possibly in combination with CFStream and, in particular, CFFTPStream.

Each of these is based on run loops, so you don't block the main thread waiting for something to happen, you just respond when it does.


How are you pausing and resuming the download?
As you said, through controlling this from the GUI, when user click the pause button, I will stop receiving the data in the background and exit the thread.

No offense, but if that's your answer, then I think you don't appreciate the nuances in the question. And if you don't appreciate the nuances, then you're probably getting them wrong.

Since the GUI operations occur on the main thread, and since you're using a background thread for the FTP operations, it's not easy to _correctly_ pause, resume, or cancel the FTP download in response to a GUI operation. If you think it is easy or direct, then it's probably not correct.

So, I ask again: what _specific_ techniques are you using to respond to a GUI action and then pause, resume, or cancel the FTP operation? You probably need to show code, or at least describe the design in technical detail, if we're going to try to help you figure out what's going wrong.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to