コード例 #1
0
ファイル: UVTimer.cs プロジェクト: sumshiny/TubumuMeeting
        public static UVTimer Every(Loop loop, TimeSpan repeat, Action callback)
        {
            var timer = new UVTimer(loop);

            timer.Tick += callback;
            timer.Start(repeat, repeat);
            return(timer);
        }
コード例 #2
0
ファイル: UVTimer.cs プロジェクト: sumshiny/TubumuMeeting
        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);
        }
コード例 #3
0
        private static Action <Exception> End(TimeSpan timeSpan, Action <Exception> callback)
        {
            UVTimer timer = null;

            Action <Exception> end = (Exception exception) =>
            {
                if (timer != null)
                {
                    timer.Close();
                    timer = null;
                    callback?.Invoke(exception);
                }
            };

            timer = UVTimer.Once(timeSpan, () => end(new TimeoutException()));

            return(end);
        }
コード例 #4
0
ファイル: UVTimer.cs プロジェクト: sumshiny/TubumuMeeting
        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);
        }