Limited retries when ancillary files are locked. (#90)
* Limited retries when anciliary files are locked. * Move sleep to top of loop.
This commit is contained in:
parent
ef31102d11
commit
d8d5f2794b
1 changed files with 22 additions and 6 deletions
|
|
@ -345,13 +345,29 @@ namespace Observatory
|
|||
// I have no idea what order Elite writes these files or if they're already written
|
||||
// by the time the journal updates.
|
||||
// Brief sleep to ensure the content is updated before we read it.
|
||||
System.Threading.Thread.Sleep(50);
|
||||
|
||||
string fileContent = File.ReadAllText(journalWatcher.Path + Path.DirectorySeparatorChar + filename);
|
||||
// Some files are still locked by another process after 50ms.
|
||||
// Retry every 50ms for 0.5 seconds before giving up.
|
||||
|
||||
var fileObject = DeserializeToEventArgs(eventType + "File", fileContent);
|
||||
JournalEntry?.Invoke(this, fileObject);
|
||||
string fileContent = null;
|
||||
int retryCount = 0;
|
||||
|
||||
while (fileContent == null || retryCount < 10)
|
||||
{
|
||||
System.Threading.Thread.Sleep(50);
|
||||
try
|
||||
{
|
||||
using var fileStream = File.Open(journalWatcher.Path + Path.DirectorySeparatorChar + filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using var reader = new StreamReader(fileStream);
|
||||
fileContent = reader.ReadToEnd();
|
||||
var fileObject = DeserializeToEventArgs(eventType + "File", fileContent);
|
||||
JournalEntry?.Invoke(this, fileObject);
|
||||
}
|
||||
catch
|
||||
{
|
||||
retryCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportErrors(List<(Exception ex, string file, string line)> readErrors)
|
||||
|
|
|
|||
Loading…
Reference in a new issue