You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
983 B
47 lines
983 B
using System.Collections.Concurrent;
|
|
|
|
namespace Easy.Realization;
|
|
|
|
internal class AutoDelayTimers
|
|
{
|
|
private static readonly Lazy<AutoDelayTimers> lazy = new(() => new AutoDelayTimers());
|
|
private static ConcurrentDictionary<string, Timer> _timers;
|
|
|
|
static AutoDelayTimers()
|
|
{
|
|
}
|
|
|
|
private AutoDelayTimers()
|
|
{
|
|
_timers = new ConcurrentDictionary<string, Timer>();
|
|
}
|
|
|
|
public static AutoDelayTimers Instance
|
|
{
|
|
get
|
|
{
|
|
return lazy.Value;
|
|
}
|
|
}
|
|
|
|
public static bool TryAdd(string key, Timer dealytimer)
|
|
{
|
|
return _timers.TryAdd(key, dealytimer);
|
|
}
|
|
|
|
public static void CloseTimer(string key)
|
|
{
|
|
if (_timers.ContainsKey(key))
|
|
{
|
|
if (_timers.TryRemove(key, out Timer timer))
|
|
{
|
|
timer?.Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool ContainsKey(string key)
|
|
{
|
|
return _timers.ContainsKey(key);
|
|
}
|
|
}
|
|
|