• 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
waitForDataInBackgroundAndNotify
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

waitForDataInBackgroundAndNotify


  • Subject: waitForDataInBackgroundAndNotify
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Wed, 2 Oct 2002 14:37:04 +0200

I have a document-based application where each document monitors a file.
Currently I do in each document:
[ NSTimer scheduledTimerWithTimeInterval: one_or_two_seconds target: self selector: @selector(periodicUpdate:) userInfo: nil repeats: YES ]

and my periodicUpdate: method does:

NSData *data = [ theFileHandle readDataToEndOfFile ] ;
unsigned int length = [ data length ] ;
if ( length > 0 )
{
// do something with the new data
}

But I think it would be more elegant if my app just waits until new data is available, instead checking every few seconds.
I have seen the FileHandle method: waitForDataInBackgroundAndNotify.
But I do not fully understand it.

Is this the way to use it:
1. document registers for NSFileHandleDataAvailableNotification
2. document creates new thread, passes the file handle to it, and the new thread does waitForDataInBackgroundAndNotify. "When the data becomes available, the thread notifies all observers with NSFileHandleDataAvailableNotification. After the notification has been posted, the thread is terminated."
3. upon receiving the notification, document reads new data and processes it.
Then back to step 2.

Is this correct? Is this really the best way to do it? Is this more efficient than my old way (periodic check)?

How does the document know that its file has changed, and not the file belonging to some other document?

Also: there is another method: waitForDataInBackgroundAndNotifyForModes: - what is this modes array good for? Yes, I can read: "modes specifies the run-loop mode (or modes) in which NSFileHandleDataAvailableNotification can be posted" but what does this mean?
I guess I do not want NSModalPanelRunLoopMode nor NSEventTrackingRunLoopMode or NSConnectionReplyMode, or do I?
And probably waitForDataInBackgroundAndNotify defaults to NSDefaultRunLoopMode, which is the mode I should want. Correct?

Gerriet.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Carbon vs Cocoa
  • Next by Date: Re: MEETING: MacOS Developer Meeting Davis, CA Fri. 10/11/02
  • Previous by thread: Re: Carbon vs Cocoa
  • Next by thread: Re: waitForDataInBackgroundAndNotify
  • Index(es):
    • Date
    • Thread