• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best way to handle this
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to handle this


  • Subject: Re: Best way to handle this
  • From: development2 <email@hidden>
  • Date: Fri, 9 Jan 2009 07:08:32 -0700


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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Best way to handle this
      • From: Graham Cox <email@hidden>
References: 
 >Best way to handle this (From: development2 <email@hidden>)
 >Re: Best way to handle this (From: Nathan Kinsinger <email@hidden>)
 >Re: Best way to handle this (From: Ken Thomases <email@hidden>)

  • Prev by Date: A Question on estimating +arrayWithCapacity
  • Next by Date: Re: A Question on estimating +arrayWithCapacity
  • Previous by thread: Re: Best way to handle this
  • Next by thread: Re: Best way to handle this
  • Index(es):
    • Date
    • Thread