diff --git a/AzureBatchQueue/TimerBatch.cs b/AzureBatchQueue/TimerBatch.cs index 00998da..a104dd8 100644 --- a/AzureBatchQueue/TimerBatch.cs +++ b/AzureBatchQueue/TimerBatch.cs @@ -15,6 +15,8 @@ internal class TimerBatch Timer? timer; BatchCompletedResult? completedResult; + readonly object locker = new(); + public TimerBatch(BatchQueue batchQueue, QueueMessage msg, int maxDequeueCount, ILogger logger) { this.batchQueue = batchQueue; @@ -85,9 +87,12 @@ async Task DoFlush() /// void DisposeTimer() { - var timerCopy = timer; - timer = null; - timerCopy.Dispose(); + lock (locker) + { + var timerCopy = timer; + timer = null; + timerCopy.Dispose(); + } } QueueMessage Message()