Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        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);
        }