can someone help me to stop timer until the method “Utils.ItsTimeToRemind(remind.FormTag);” is finished? Then start again…
public static Timer TIMER;
public TimerClass()
{
TimerCallback callback = new TimerCallback(Tick);
TIMER = new Timer(callback, null, 0, 1000);
}
static public void Tick(Object stateInfo)
{
List<RemindObject> remList = Utils.Reminds;
foreach (RemindObject remind in remList)
{
if (remind.reminTime.CompareTo(DateTime.Now) < 0)
{
Utils.ItsTimeToRemind(remind.FormTag);
}
}
}
There is a small problem with Neil Knight’s solution – it’s better to start/stop your timer in a
try-catchblock. If an exception is thrown you can ensure that the timer will be restarted: