开发者

Is there any sort of File system transaction mechanism available to .net application?

I'm implementing a simple update mechanism for an application I'm writing the last part of the update process consist in renaming the current application executable file from something like myApp.exe to myApp.old.exe and then renaming the freshly downloaded and updated file from myApp.new.exe to myApp开发者_JAVA技巧.exe.

I'd like to find a way for theses two operation to be atomic, because if my application crash (for any reason, like an asteroids falling on a power line) after it renamed itself and before it renamed the new version, it will be stuck in a state where it can't be restarted by using the usual shortcuts, so it won't be able to finish it's update.

So is there anyway to make the update failsafe?


On 2008/Vista upward yes, though it is not exposed. At that point, NTFS got file system transactions on the file system / kernel level.

Please check:

http://www.michaelckennedy.net/blog/2007/12/07/SystemTransactionsAndWindowsVistaNTFSUpdated.aspx

http://www.codeguru.com/cpp/misc/misc/fileio/article.php/c9987

http://xavierdecoster.wordpress.com/2009/10/18/transactional-ntfs-txf/

They have code samples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜