예제 #1
0
        public static UVTimer Once(Loop loop, TimeSpan timeout, Action callback)
        {
            var timer = new UVTimer(loop);

            timer.Tick += () =>
            {
                callback?.Invoke();
                timer.Close();
            };
            timer.Start(timeout, TimeSpan.Zero);
            return(timer);
        }
예제 #2
0
        public static UVTimer Times(Loop loop, int times, TimeSpan repeat, Action <int> callback)
        {
            var timer = new UVTimer(loop);
            int i     = 0;

            timer.Tick += () =>
            {
                i++;
                if (callback != null)
                {
                    callback(i);
                }
                if (i >= times)
                {
                    timer.Close();
                }
            };
            timer.Start(repeat, repeat);
            return(timer);
        }