Skip to content

Commit

Permalink
Synchronize threads on Timer dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslav-tykhonchuk committed Dec 18, 2023
1 parent 2d48b2c commit 7a16c43
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions AzureBatchQueue/TimerBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal class TimerBatch<T>
Timer? timer;
BatchCompletedResult? completedResult;

readonly object locker = new();

public TimerBatch(BatchQueue<T> batchQueue, QueueMessage<T[]> msg, int maxDequeueCount, ILogger logger)
{
this.batchQueue = batchQueue;
Expand Down Expand Up @@ -85,9 +87,12 @@ async Task DoFlush()
/// </summary>
void DisposeTimer()
{
var timerCopy = timer;
timer = null;
timerCopy.Dispose();
lock (locker)
{
var timerCopy = timer;
timer = null;
timerCopy.Dispose();

Check warning on line 94 in AzureBatchQueue/TimerBatch.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 94 in AzureBatchQueue/TimerBatch.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 94 in AzureBatchQueue/TimerBatch.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 94 in AzureBatchQueue/TimerBatch.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}

QueueMessage<T[]> Message()
Expand Down

0 comments on commit 7a16c43

Please sign in to comment.