file rename woes - want atomic operation...

  • Thread starter spacehopper_man
  • Start date
S

spacehopper_man

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
 
G

Guest

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/issues/06/07/BeyondWinFX/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top