Skip to content

Commit 3f298b4

Browse files
committed
Start task in constructor.
1 parent affe253 commit 3f298b4

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Microsoft.IdentityModel.Tokens/EventBasedLRUCache.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal class EventBasedLRUCache<TKey, TValue>
5959
private int _compactValuesState = ActionNotQueued;
6060
private int _removeExpiredValuesState = ActionNotQueued;
6161
private int _processCompactedValuesState = ActionNotQueued;
62-
private Task _eventQTask;
62+
private readonly Task _eventQTask;
6363
private int _eventQueuePollingInterval = 50; // in milliseconds
6464
// for testing purpose only to verify the task count
6565
private int _taskCount;
@@ -112,6 +112,7 @@ internal EventBasedLRUCache(
112112
_compactIntervalInSeconds = compactIntervalInSeconds;
113113
_timeForNextExpiredValuesRemoval = DateTime.UtcNow.AddSeconds(_removeExpiredValuesIntervalInSeconds);
114114
_maintainLRU = maintainLRU;
115+
_eventQTask = Task.Run(EventQueueTaskAction);
115116
}
116117

117118
/// <summary>
@@ -136,9 +137,6 @@ internal EventBasedLRUCache(
136137

137138
private void AddActionToEventQueue(Action action)
138139
{
139-
if (_eventQTask == null || _eventQTask.Status != TaskStatus.Running)
140-
_eventQTask = Task.Run(EventQueueTaskAction);
141-
142140
_eventQueue.Enqueue(action);
143141
}
144142

0 commit comments

Comments
 (0)