mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-12 03:57:27 +00:00
feature: add fileLock for reads
This commit is contained in:
parent
33c7038d99
commit
f902a57f60
1 changed files with 44 additions and 17 deletions
|
|
@ -78,6 +78,8 @@ namespace PepperDash.Essentials.Core
|
|||
public static string ReadDataFromFile(FileInfo file)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fileLock.TryEnter())
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
|
||||
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
|
||||
|
|
@ -94,6 +96,12 @@ namespace PepperDash.Essentials.Core
|
|||
Debug.Console(2, "File {0} does not exsist", file.FullName);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -101,6 +109,12 @@ namespace PepperDash.Essentials.Core
|
|||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||
return "";
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (fileLock != null && !fileLock.Disposed)
|
||||
fileLock.Leave();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -132,6 +146,8 @@ namespace PepperDash.Essentials.Core
|
|||
{
|
||||
string data;
|
||||
try
|
||||
{
|
||||
if (fileLock.TryEnter())
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
|
||||
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
|
||||
|
|
@ -150,6 +166,11 @@ namespace PepperDash.Essentials.Core
|
|||
data = "";
|
||||
}
|
||||
GotFileEvent.Invoke(null, new FileEventArgs(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -157,6 +178,12 @@ namespace PepperDash.Essentials.Core
|
|||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
|
||||
data = "";
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (fileLock != null && !fileLock.Disposed)
|
||||
fileLock.Leave();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue