示例#1
0
    //替换定时任务
    public bool ReplaceTimeTask(int tID, Action callBack, double delay, ETimeUnit type = ETimeUnit.Millisecond, int count = 1)
    {
        delay *= (int)type;
        bool     find     = false;
        TimeTask timeTask = new TimeTask(callBack, GetNowUTCTime() + delay, count, delay, tID);

        //替换
        for (int i = 0; i < timeTaskList.Count; i++)
        {
            if (tID == timeTaskList[i].tID)
            {
                timeTaskList[i] = timeTask;
                find            = true;
                break;
            }
        }
        for (int i = 0; i < tempTimeTaskList.Count; i++)
        {
            if (tID == tempTimeTaskList[i].tID)
            {
                tempTimeTaskList[i] = timeTask;
                find = true;
                break;
            }
        }
        return(find);
    }
示例#2
0
    //添加定时任务
    public int AddTimeTask(Action callBack, double delay, ETimeUnit type = ETimeUnit.Millisecond, int count = 1)
    {
        delay *= (int)type;
        int      tID      = GetTID();
        TimeTask timeTask = new TimeTask(callBack, GetNowUTCTime() + delay, count, delay, tID);

        tempTimeTaskList.Add(timeTask);
        tIDList.Add(tID);
        return(tID);
    }
示例#3
0
        public Time(double value, ETimeUnit unit)
        {
            if (value < 0.0)
            {
                throw new ArgumentException("Negative times are not allowed");
            }

            Value    = value;
            Unit     = unit;
            _awaiter = new Awaiter(this);
        }
示例#4
0
        /// <summary>
        /// Expresses the encoded time in a different unit.
        /// </summary>
        /// <example>
        /// <code>new Time(42.0, ETimeUnit.sec).ScalteTo(ETimeUnit.ms)</code> returns 42000.0
        /// </example>
        /// <param name="destUnit">The destination time unit</param>
        /// <returns>The value in terms of the destination time unit.</returns>
        public double ScaleTo(ETimeUnit destUnit)
        {
            double result = Value;

            while (destUnit < Unit)
            {
                result *= 1e-3;
                ++destUnit;
            }
            while (destUnit > Unit)
            {
                result *= 1e3;
                --destUnit;
            }
            return(result);
        }
示例#5
0
 /// <summary>
 /// Creates a time instance.
 /// </summary>
 public static Time Create(double value, ETimeUnit unit)
 {
     return(new Time(value, unit));
 }
示例#6
0
 //替换定时任务
 public bool ReplaceTimeTask(int tID, Action callBack, float delay, ETimeUnit type = ETimeUnit.Millisecond, int count = 1)
 {
     return(myTimer.ReplaceTimeTask(tID, callBack, delay, type, count));
 }
示例#7
0
 //添加定时任务
 public int AddTimeTask(Action callBack, float delay, ETimeUnit type = ETimeUnit.Millisecond, int count = 1)
 {
     return(myTimer.AddTimeTask(callBack, delay, type, count));
 }