Skip to content

Commit cec25c0

Browse files
author
Anson.G
committed
bugfix delay remove
1 parent 02754e8 commit cec25c0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

FastCache.InMemory/Extension/DictExtension.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ public static bool TryRemove<TKey, TValue>(this ConcurrentDictionary<TKey, TValu
1212
var res = dictionary.TryRemove(key, out value);
1313
if (res && seconds > 0)
1414
{
15-
Task.Delay(TimeSpan.FromSeconds(seconds)).ContinueWith(_ => { dictionary.TryRemove(key, out var _); });
15+
Task.Run(async () =>
16+
{
17+
await Task.Delay(TimeSpan.FromSeconds(seconds));
18+
lock (dictionary)
19+
{
20+
dictionary.TryRemove(key, out var _);
21+
}
22+
});
1623
}
1724
return res;
1825
}

0 commit comments

Comments
 (0)