Esempio n. 1
0
        /// <summary>
        /// 今天指定时间做调用,hour(18:30填18.5),method(调用的函数),args(函数参数)
        /// </summary>
        /// <param name="hour"></param>
        /// <param name="method"></param>
        /// <param name="args"></param>
        public static void RegTodayTimerEvent(float hour, TimerMethod method, object args = null)
        {
            if (method == null)
            {
                return;
            }
            if (todayHandlers.hash.ContainsKey(method))
            {
                return;
            }

            TodayTimerHandler handler = new TodayTimerHandler();
            TimerEvent        events  = new TimerEvent(args);

            events.key     = method;
            handler.method = method;
            handler.args   = events;
            handler.hour   = hour;
            System.DateTime now     = System.DateTime.Now;
            int             phour   = (int)hour;
            int             pminute = (int)(60 * (hour - phour));

            if (now.Hour >= phour && now.Minute >= pminute)
            {
                handler.isTodayExe = true;
            }
            else
            {
                handler.isTodayExe = false;
            }
            handler.lastTime = System.DateTime.Now;
            todayHandlers.addElement(method, handler);
        }
Esempio n. 2
0
        public async Task UpdateHub(CommandContext ctx)
        {
            TimerMethod.UpdateHubInfo(true);
            DiscordMessage msg = await ctx.RespondAsync("TCHub info has been force updated.");

            await Task.Delay(10000).ContinueWith(f => msg.DeleteAsync());
        }
Esempio n. 3
0
        /// <summary>
        /// 执行计时器回调函数;
        /// </summary>
        /// <param name="value"></param>
        protected static void runTodayTimerMethod(TodayTimerHandler value)
        {
            TimerMethod method = value.method;

            if (method != null)
            {
                method(value.args);
            }
        }
Esempio n. 4
0
        static void Main(string[] args)

        {
            TimerMethod testMethod = Method1;

            testMethod += Method2;
            var timer = new Timer(25, testMethod);

            timer.Run();
        }
Esempio n. 5
0
 /// <summary>
 /// 执行计时器回调函数;
 /// </summary>
 /// <param name="value"></param>
 protected static void runTimerMethod(TimerHandler value)
 {
     try
     {
         TimerMethod method = value.method;
         if (method != null)
         {
             method(value.args);
         }
     }
     catch (System.Exception ex)
     {
         Log.Log.Server.Warning(ex.ToString());
     }
 }
Esempio n. 6
0
        public static void Run()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("07. Timer with delegate");

            Console.ForegroundColor = ConsoleColor.White;
            TimerMethod testDelegate = TestMethod;

            testDelegate += AnotherTestMetod;
            testDelegate += delegate
            {
                Console.WriteLine("I am Anonimus Method");
            };
            Timer testTimer = new Timer(5, 2, testDelegate);

            testTimer.Run();
        }
Esempio n. 7
0
        //创建计时器;
        protected static System.Object create(bool useFrame, bool repeat, float delay, TimerMethod method, object args, bool cover = false)
        {
            System.Object key;
            if (cover)
            {
                //先删除相同函数的计时;
                clearTimer(method);
                key = method;
            }
            else
            {
                key = index++;
            }

            TimerHandler handler;

            if (pool.Count > 0)
            {
                handler = (TimerHandler)pool[pool.Count - 1];
                pool.RemoveAt(pool.Count - 1);
            }
            else
            {
                handler = new TimerHandler();
            }


            TimerEvent events = new TimerEvent(args);

            events.key        = key;
            handler.userFrame = useFrame;
            handler.repeat    = repeat;
            handler.delay     = delay;
            handler.method    = method;
            handler.args      = events;
            handler.exeTime   = delay + (useFrame ? currentFrame : currentTime);
            handlers.addElement(key, handler);
            count++;
            return(key);
        }
Esempio n. 8
0
 /**清理;*/
 public void clear()
 {
     method = null;
     args   = null;
 }
Esempio n. 9
0
 public Timer(byte ticks, int seconds, TimerMethod currentMethod)
 {
     this.Ticks    = ticks;
     this.Interval = seconds;
     this.Method   = currentMethod;
 }
Esempio n. 10
0
 /**定时执行一次(基于帧率);
  * @param	delay  延迟时间(单位为帧);
  * @param	method 结束时的回调方法;
  * @param	args   回调参数;
  * @param	cover  是否覆盖(true:同方法多次计时,后者覆盖前者。false:同方法多次计时,不相互覆盖);
  * @return  cover=true时返回回调函数本身,cover=false时,返回唯一ID,均用来作为clearTimer的参数;*/
 public static System.Object doFrameOnce(float delay, TimerMethod method, object args = null, bool cover = false)
 {
     return(create(true, false, delay, method, args, cover));
 }
Esempio n. 11
0
 public Timer(int seconds, TimerMethod method)
 {
     this.Seconds = seconds;
     this.Method  = method;
 }