Prevent multiple processes from reading same file.

This commit is contained in:
glax 2023-04-21 11:01:05 +02:00
parent 8b7cfcbd77
commit 1facca84ba

View File

@ -39,11 +39,21 @@ namespace Pathfinding
{
if (!File.Exists(filePath))
return null;
FileStream regionFile = new (filePath, FileMode.Open);
Region retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
regionFile.Dispose();
return retRegion;
while (true)
{
try
{
FileStream regionFile = new (filePath, FileMode.Open);
Region retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
regionFile.Dispose();
return retRegion;
}catch(IOException)
{
Thread.Sleep(10);
}
}
}
private Region? RegionFromId(ulong regionId)