[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5039
  • Last Modified:

Create File Lock

I need to test a program of our that is having issues with file locks when the load on the system is high.  I need to simualte a file lock that will not give me access to the file.  Is there a quick and easy way to make a file lock exclusive in C#?
1 Solution
You can use File.Open Method (String, FileMode, FileAccess, FileShare) to open file in Open mode, Read access and None sharing. All time FileStream instance returned by this method exists and not disposed, file is locked.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now