I need to implement Oplock (opportunistic locking) in .NET project. Here is the scenario that I need to implement:
- App 1 opens the file and does NOT allow writing (for example, opens a file with
FileShare.Read
). - App 2 requests writing to the file (opens a file with
FileAccess.Write
). - App 1 receives a notification that the writing is requested. It confirms breaking the lock and allows App 2 to write to the file.
There is a full asynchronous I/O support in the FileStream
class and there is also NativeOverlapped
structure in .NET. Looks like .NET has everything needed for Oplock. However there is no any example how to use NativeOverlapped
and NativeOverlapped.EventHandle
field required to handle the oplock break and no any parameters for this structure.
Is Oplock is supported in .NET at all? Are there any Oplock example?