diff --git a/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs b/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs index 7e2f73a..d8f5ba6 100644 --- a/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs +++ b/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs @@ -8,6 +8,7 @@ using System.IO.Compression; using System.Text; using System.Text.Json; +using System.Threading; namespace Nodsoft.WowsReplaysUnpack.Services; @@ -21,6 +22,7 @@ public sealed class ReplayUnpackerService : ReplayUnpackerService, private readonly JsonSerializerOptions _jsonSerializerOptions = new() { PropertyNameCaseInsensitive = true }; private readonly IReplayDataParser _replayDataParser; private readonly IReplayController _replayController; + private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1); public ReplayUnpackerService(IReplayDataParser replayDataParser, TController replayController) { @@ -69,7 +71,7 @@ Seek to offset 4 in the replay file (skipping the magic number) See http://wiki.vbaddict.net/pages/File_Replays for more details. */ options ??= new(); - + _semaphore.Wait(); BinaryReader binaryReader = new(stream); byte[] signature = binaryReader.ReadBytes(4); @@ -103,7 +105,7 @@ Seek to offset 4 in the replay file (skipping the magic number) { _replayController.HandleNetworkPacket(networkPacket, options); } - + _semaphore.Release(); return replay; }