Thread: Temporary lock file access in .net

  1. #1
    Registered User
    Join Date
    Oct 2008

    Temporary lock file access in .net

    I'd like to know if there is an elegant way in .net for temporarily locking the access to a set of files to other users.
    I can handle (copy, move etc.) something like 100 files in one shot, the files being given with wildcards in path name, so I need a simple way to process all the files and provide transaction integrity.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    File.Copy() and File.Move() will internally open the source file in exclusive mode and release the lock once the operation is done. So you don't need to do anything in terms of explicitly locking the files yourself. Note however this means you should wrap it inside a Try/Catch block since if another process has that file for itself, your copy operation will throw an exception.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 10:18 AM