|
FilePathGetFileLockT Method
|
Gets a lock on the file using the given lock function.
Namespace: GSF.IOAssembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax 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
)
static member GetFileLock :
fileName : string *
lockFunction : Func<string, 'T> *
?secondsToWait : float *
?retryMilliseconds : int
(* Defaults:
let _secondsToWait = defaultArg secondsToWait 5
let _retryMilliseconds = defaultArg retryMilliseconds 200
*)
-> 'T
JavaScript does not support generic types or methods.
View SourceParameters
- 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.
Type Parameters
- T
- The return value of the lock function.
Return Value
TThe return value of the lock function.
Remarks
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))
{
}
using (FileStream stream = GetFileLock(File.Create))
{
}
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.
See Also