FilePathGetFileLockT Method
Gets a lock on the file using the given lock function.
Namespace: Gemstone.IOAssembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.110 -- Release Build+3e0464f4461df4d3e1175b13966eb47ff832554d
public static T GetFileLock<T>(
string fileName,
Func<string, T> lockFunction,
double secondsToWait = 5,
int retryMilliseconds = 200
)
Public Shared Function GetFileLock(Of T) (
fileName As String,
lockFunction As Func(Of String, T),
Optional secondsToWait As Double = 5,
Optional retryMilliseconds As Integer = 200
) As T
public:
generic<typename T>
static T GetFileLock(
String^ fileName,
Func<String^, T>^ lockFunction,
double secondsToWait = 5,
int retryMilliseconds = 200
)
JavaScript does not support generic types or methods.
- fileName String
- The name of the on which the lock is to be obtained.
- lockFunction FuncString, T
- The function to be called in order to get the file lock.
- secondsToWait Double (Optional)
- The number of seconds to wait before giving up on the file lock.
- retryMilliseconds Int32 (Optional)
- The number of milliseconds to wait between attempts to obtain the file lock.
- T
- The return value of the lock function.
TThe return value of the lock function.
The intent of this function is to provide a sane method for opening
a file which may produce errors due to read/write contention.
Usage of this class is fairly simple using the static methods
built into the File class.
using (StreamReader reader = GetFileLock(File.OpenText))
{
// Read lines from the file
}
using (FileStream stream = GetFileLock(File.Create))
{
// Write bytes into the file
}
This method will only retry if an IOException
occurs while executing the lockFunction.
After retrying for at least secondsToWait
seconds, this function will throw the last IOException it encountered.