Prevent multiple processes from reading same file.
This commit is contained in:
parent
8b7cfcbd77
commit
1facca84ba
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user