On Jan 8, 2009, at 11:58 PM, Ken Thomases wrote:

On Jan 8, 2009, at 7:49 PM, Nathan Kinsinger wrote:

On Jan 8, 2009, at 4:20 PM, development2 wrote:

I am hoping someone can help me figure out the best way to handle this, I am sure someone out there has some experience with this.

I have some code that sends a command to an external hardware device and waits to get the response back with the info that was requested of the device. Now what I want to do is animate on screen the graphic of the device, showing that it is working. What I tried to do at first was setup an NSTimer that would be called every 1 second say, then call my method to call the device and wait for the device to respond. But basically my call blocks the NSTimer because it takes some time (actually what I am calling from my code is a command line tool that we created that will return a result file to us). So what I want to do is call my method to get the device info and while waiting for the response animate this graphic of the device in operation. What is the best way to do this?

1) Should I use an NSThread for this?
2) IS there some other Cocoa functionality that might help me here?

Thanks in advance for any help.

The short answer, yes you need to use threads.

I disagree.

The OP is invoking an external program to do the communication, but is unnecessarily blocking while waiting for that program to complete. I suggest using NSTask if that's not already what you're doing. Then use the asynchronous notifications of when it completes, and the asynchronous methods of NSFileHandle to do the communication, so that you don't block while waiting for it.

Thanks,

But I am curious about something. I am using NSTask to actually handle the external program, so what asynchronous notifications are you talking about then?




Using NSTimer for the animation will then work. You will also be able to implement something like a Cancel button. That is, by not blocking, your UI can remain responsive.

Cheers,
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