Ejemplo n.º 1
0
    public int AddTimeTask(Action <int> callback, double delay, WinterTimeUnit timeUnit = WinterTimeUnit.Millisecond, int count = 1)
    {
        if (timeUnit != WinterTimeUnit.Millisecond)
        {
            switch (timeUnit)
            {
            case WinterTimeUnit.Second:
                delay = delay * 1000;
                break;

            case WinterTimeUnit.Minute:
                delay = delay * 1000 * 60;
                break;

            case WinterTimeUnit.Hour:
                delay = delay * 1000 * 60 * 60;
                break;

            case WinterTimeUnit.Day:
                delay = delay * 1000 * 60 * 60 * 24;
                break;

            default:
                LogInfo("Add Task TimeUnit Type Error...");
                break;
            }
        }
        int tid = GetTid();;

        nowTime = GetUTCMilliseconds();
        lock (lockTime) {
            tmpTimeLst.Add(new WinterTimeTask(tid, callback, nowTime + delay, delay, count));
        }
        return(tid);
    }
Ejemplo n.º 2
0
    public bool ReplaceTimeTask(int tid, Action <int> callback, float delay, WinterTimeUnit timeUnit = WinterTimeUnit.Millisecond, int count = 1)
    {
        if (timeUnit != WinterTimeUnit.Millisecond)
        {
            switch (timeUnit)
            {
            case WinterTimeUnit.Second:
                delay = delay * 1000;
                break;

            case WinterTimeUnit.Minute:
                delay = delay * 1000 * 60;
                break;

            case WinterTimeUnit.Hour:
                delay = delay * 1000 * 60 * 60;
                break;

            case WinterTimeUnit.Day:
                delay = delay * 1000 * 60 * 60 * 24;
                break;

            default:
                LogInfo("Replace Task TimeUnit Type Error...");
                break;
            }
        }
        nowTime = GetUTCMilliseconds();
        WinterTimeTask newTask = new WinterTimeTask(tid, callback, nowTime + delay, delay, count);

        bool isRep = false;

        for (int i = 0; i < taskTimeLst.Count; i++)
        {
            if (taskTimeLst[i].tid == tid)
            {
                taskTimeLst[i] = newTask;
                isRep          = true;
                break;
            }
        }

        if (!isRep)
        {
            for (int i = 0; i < tmpTimeLst.Count; i++)
            {
                if (tmpTimeLst[i].tid == tid)
                {
                    tmpTimeLst[i] = newTask;
                    isRep         = true;
                    break;
                }
            }
        }

        return(isRep);
    }