• 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: accessing newly-created files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: accessing newly-created files


  • Subject: Re: accessing newly-created files
  • From: "David Piasecki" <email@hidden>
  • Date: Thu, 15 Apr 2004 14:18:06 -0700

Hmmm... spinning ball of doom is bad. I saw the sleepUntilDate method, but I decided to wait to try it until I knew more about it. I'd like to avoid the beach ball if at all possible. I haven't used try {} catch {} blocks with Objective-C yet. I don't see any of that in the two Cocoa/Objective-C books that I have. Is there something similar where I can catch the file I/O error and then continue once it works?

David


On Apr 15, 2004, at 2:08 PM, Louis C. Sacha wrote:

Hello...

Perhaps something like the following would work?


NSImage *theImage = nil;

while (!theImage)
{
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
theImage = [[NSImage alloc] initWithContentsOfFile:@"/the/path/to/the/file.img"];
}


Note that if you use the sleepUntilDate: method on the main thread continuously (or with a long time interval) you will get the spinning beachball cursor.

Hope that helps,

Louis


I use a system call to execute a program which creates an image file that I want to display directly after it is written. For some reason, it seems to tell the OS to write the file, and then it returns before the file is actually written. So when my next call attempts to read the file, I get an error. I got around this by calling the standard C sleep function; however, sleep only takes increments of seconds. 1 second was plenty of time for the ~30K file to be written, but I'd rather not wait that long, and it's not a good way of handling things. Rather, I would like to perform a check for the status of the file to make sure it's all there before attempting a read operation. Is there a way to do this?

David
_______________________________________________
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.


References: 
 >accessing newly-created files (From: "David Piasecki" <email@hidden>)
 >Re: accessing newly-created files (From: "Louis C. Sacha" <email@hidden>)

  • Prev by Date: Re: C++ templates?
  • Next by Date: Re: C++ templates?
  • Previous by thread: Re: accessing newly-created files
  • Next by thread: Re: accessing newly-created files
  • Index(es):
    • Date
    • Thread