Изобрел свой таймер
public class WorkTimer : Disposable
{
private readonly System.Threading.Timer timer;
private readonly TimerCallback timerCallback;
private int interval;
private bool timerIsCalling = false;
public WorkTimer(TimerCallback callback, object state, int dueTime, int interval)
{
timerCallback = callback;
Interval = interval;
timer = new System.Threading.Timer(Callback, state, dueTime, Interval);
}
protected override void ReleaseUnmanagedResources()
{
timer?.Dispose();
}
public int Interval
{
get { OnCallAnyMethod(); return interval; }
set {
OnCallAnyMethod();
interval = value;
if (!timerIsCalling)
timer?.Change(value, value);
}
}
private void Callback(object state)
{
timerIsCalling = true;
timer.Change(-1, -1); // Stop timer
this.timerCallback(state);
timer.Change(Interval, Interval); // Resume timer
timerIsCalling = false;
}
}