wtt
2024-09-20 d9b200d424889c069953ec084ef9d4dd6c4ff66b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
 
namespace Taobao.Top.Link
{
    /// <summary>easy timer impl
    /// </summary>
    public class ResetableTimer
    {
        //min=50ms by .net impl
        private Timer _timer;
        private int _periodMillisecond;
        public event EventHandler Elapsed;
 
        public ResetableTimer(int periodMillisecond)
        {
            this._periodMillisecond = periodMillisecond;
            this._timer = new Timer(o =>
            {
                if (Elapsed != null)
                {
                    this.Elapsed(null, null);
                }
            }, null
            , this._periodMillisecond
            , this._periodMillisecond);
        }
        /// <summary>cancel timer
        /// </summary>
        public void Cancel()
        {
            if (this._timer == null)
                return;
            this._timer.Dispose();
            this._timer = null;
        }
        /// <summary>delay in period
        /// </summary>
        public void Delay()
        {
            this._timer.Change(this._periodMillisecond, this._periodMillisecond);
        }
    }
}