Re: accessing newly-created files
Re: accessing newly-created files
- Subject: Re: accessing newly-created files
- From: Brian Bergstrand <email@hidden>
- Date: Thu, 15 Apr 2004 17:11:02 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
A thread is really overkill for this situation.
If you can restrict your self to panther, the correct way to do this
would be to open a knote on the parent dir and wait for a creation
event, check to see if your file exists, and wait again if it doesn't.
You can give kevent() a sub-second timeout, so this shouldn't cause
the beach ball.
I wrote some simple sample code for knotes at:
<
http://cvs.sourceforge.net/viewcvs.py/ext2fsx/test/kqwatch.c>
If you have to run on Jag or earlier, then a combo of stat and usleep
should serve your needs. stat will quickly tell you if a file exists,
and usleep allows microsecond sleep times. man for more info..
HTH.
On Apr 15, 2004, at 4: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
>
Brian Bergstrand <
http://www.bergstrand.org/brian/>, AIM: triryche206
PGP Key: <
http://www.bergstrand.org/brian/misc/public_key.txt>
Life is a multimedia of sins so he who collects the most porn wins. -
U.F. 000307
As of 05:00:06 PM, iTunes is playing "I Don't Believe In Love" from
"Operation Livecrime" by "Queensrche"
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3
iQA/AwUBQH76a3nR2Fu2x7aiEQJ4gQCfWxETCgSQjkp2gXtE+SohiZN0BlMAoIAC
mAm4Fubg7GrzN/GkpkgXsxW/
=4bQc
-----END PGP SIGNATURE-----
_______________________________________________
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.