/// <summary> /// Autostarts timer /// </summary> /// <param name="EAMethod"></param> /// <param name="interval"></param> /// <param name="ID"></param> /// <param name="Exceptions"></param> /// <param name="waitForAccess"></param> /// <returns></returns> public bool Run(Expression <Action> EAMethod, int interval, string ID = null, bool Exceptions = true, bool waitForAccess = false) { if (EAMethod == null) { return(false); } if (MaxThreadsCount < TDSTTimers.Count) { if (!waitForAccess) { return(false); } while (MaxThreadsCount <= TDSTTimers.Count) { Thread.Sleep(1); } } if (System.String.IsNullOrEmpty(ID)) { ID = Expressions.nameofFull(EAMethod); } ThreadedTimer TTimer = Timer(ID); if (TTimer != null && TTimer.Enabled) { return(false); } TTimer = new ThreadedTimer(EAMethod, interval, true); TDSTTimers.Add(ID, TTimer); TDSTTimers[ID].Start(); return(true); // return this.Run(EAMethod, interval, ID, Exceptions, waitForAccess, true); }
public bool Run(Expression <Action> EAMethod, int interval, string ID = null, bool waitForAccess = true, bool autostart = true) { if (EAMethod == null) { return(false); } if (MaxThreadsCount < Workers.Count) { if (!waitForAccess) { return(false); } while (MaxThreadsCount <= Workers.Count) { Thread.Sleep(1); } } if (ID.IsNullOrEmpty()) { ID = Expressions.nameofFull(EAMethod); } lock (locker) { ThreadedTimer TTimer = Workers.ContainsKey(ID) ? Workers[ID] : null; if (TTimer != null && TTimer.Enabled) { return(false); } TTimer = new ThreadedTimer(EAMethod, interval, autostart); Workers.Add(ID, TTimer, true); Workers[ID].Start(); } return(true); }
public bool Run(Expression <Action> EAMethod, int interval, string ID, bool waitForAccess, bool autostart) { if (EAMethod == null) { return(false); } if (MaxThreadsCount < TDSTTimers.Count) { if (!waitForAccess) { return(false); } while (MaxThreadsCount <= TDSTTimers.Count) { Thread.Sleep(1); } } if (ID.IsNullOrEmpty()) { ID = Expressions.nameofFull(EAMethod); } ThreadedTimer TTimer = Timer(ID); if (TTimer != null && TTimer.Enabled) { return(false); } TTimer = new ThreadedTimer(EAMethod, interval, autostart); TDSTTimers.Add(ID, TTimer); TDSTTimers[ID].Start(); return(true); }