Skip to content

Commit c2f7447

Browse files
committed
Fix clientside timers threadsafety
1 parent f842fc9 commit c2f7447

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

api/AltV.Net.Client/Elements/Pools/TimerPool.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using AltV.Net.Client.Elements.Interfaces;
1+
using System.Collections.Concurrent;
2+
using AltV.Net.Client.Elements.Interfaces;
23

34
namespace AltV.Net.Client.Elements.Pools
45
{
56
public class TimerPool : ITimerPool
67
{
78
private uint lastId;
8-
private readonly Dictionary<uint, IModuleTimer> timers = new();
9+
private readonly ConcurrentDictionary<uint, IModuleTimer> timers = new();
910

1011
public static long GetTime()
1112
{
@@ -30,13 +31,13 @@ public void Tick(string resourceName)
3031
public uint Add(IModuleTimer timer)
3132
{
3233
var id = lastId++;
33-
timers.Add(id, timer);
34+
timers.TryAdd(id, timer);
3435
return id;
3536
}
3637

3738
public void Remove(uint id)
3839
{
39-
timers.Remove(id);
40+
timers.TryRemove(id, out _);
4041
}
4142
}
4243
}

0 commit comments

Comments
 (0)