Skip to content

Commit 6286b8b

Browse files
author
DwGoing
committed
🐞 fix: 高并发时的InvalidOperationException
1 parent f060a26 commit 6286b8b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/DwFramework.Core/Plugins/Time/StopwatchManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
2+
using System.Collections.Concurrent;
33

44
namespace DwFramework.Core.Time
55
{
@@ -34,7 +34,7 @@ private sealed class Stopwatch
3434
public long GetTotalSeconds() => GetTotalMilliseconds() / 1000;
3535
}
3636

37-
private static Dictionary<string, Stopwatch> _stopwatches = new();
37+
private static ConcurrentDictionary<string, Stopwatch> _stopwatches = new();
3838

3939
/// <summary>
4040
/// 创建计时器
@@ -68,7 +68,7 @@ public static void SetStartTime(string tag, DateTime startTime)
6868
public static void Remove(string tag)
6969
{
7070
if (!_stopwatches.ContainsKey(tag)) return;
71-
_stopwatches.Remove(tag);
71+
_stopwatches.RemoveWhere(item => item.Key == tag);
7272
}
7373

7474
/// <summary>

0 commit comments

Comments
 (0)