471,595 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

file rename woes - want atomic operation...

no "rename" operation in C# !!!

- this has been covered in this group before, but I can't find any good
answers.

what I am trying to do is refresh the content in a file with minimum
performance impact on any read operations to that file - a common task
right....

in the unix world the way to do this is to create a temporary file with
the new content, and "rename" the temporary file to the destination
file. This works because the rename operation is atomic in the sense
that the old file is removed and the new file moved without the chance
of some other process accessing the file in between.

this operation is also fast as the rename does not actually move any of
the data on disk (it's an inode manipulation).

....I can't find how to do this in C# !

the File.Move operation is no good because it throws an exception if
the target file already exists.

File.Delete, File.Move is also no good because it is not atomic....

any ideas?

thanks,

Oli@TigerTechSoftware

Nov 2 '06 #1
1 4294
It's a well-known issue. The reason is that there is no resource manager for
the file system (your can realize your own, and we can only with u good luck
with this :))

BTW, they solve this only in Vista API and introduced this as KTM (Kernel
Transaction Manager). You can read about it there
http://msdn.microsoft.com/msdnmag/is...X/default.aspx with
sample that u noted.

And now there is nothing else better then just handing exeption (as used in
that article) in case if file exists
--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"sp*************@yahoo.com" wrote:
no "rename" operation in C# !!!

- this has been covered in this group before, but I can't find any good
answers.

what I am trying to do is refresh the content in a file with minimum
performance impact on any read operations to that file - a common task
right....

in the unix world the way to do this is to create a temporary file with
the new content, and "rename" the temporary file to the destination
file. This works because the rename operation is atomic in the sense
that the old file is removed and the new file moved without the chance
of some other process accessing the file in between.

this operation is also fast as the rename does not actually move any of
the data on disk (it's an inode manipulation).

....I can't find how to do this in C# !

the File.Move operation is no good because it throws an exception if
the target file already exists.

File.Delete, File.Move is also no good because it is not atomic....

any ideas?

thanks,

Oli@TigerTechSoftware

Nov 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Willem van Isselmuden | last post: by
4 posts views Thread by Patrick de Ridder | last post: by
7 posts views Thread by Joe HM | last post: by
9 posts views Thread by Mark | last post: by
3 posts views Thread by Bill Ross | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.