Пример #1
0
 internal SchedulerTask(SchedulerCallback callback, bool isBackground)
     : this()
 {
     if (callback == null) throw new ArgumentNullException("callback");
     Callback = callback;
     IsBackground = isBackground;
 }
Пример #2
0
 internal SchedulerTask([NotNull] SchedulerCallback callback, bool isBackground, [CanBeNull] object userState)
     : this()
 {
     Callback     = callback ?? throw new ArgumentNullException(nameof(callback));
     IsBackground = isBackground;
     UserState    = userState;
 }
        private void SetNextTrigger(string id, ITrigger trigger, SchedulerCallback callback)
        {
            var milliSeconds = GetMilliSecondsToNextTrigger(trigger);

            bool isNotIntermediateCallback = true;
            long max = int.MaxValue * 2L;
            if (milliSeconds > max)
            {
                isNotIntermediateCallback = false;
                milliSeconds = max;
            }

            TimerCallback timerCallback = s =>
            {
                if (TimerIsNotCancelled(id))
                {
                    if (isNotIntermediateCallback)
                    {
                        InvokeCallbackAndSetNextTrigger(id, trigger, callback);
                    }
                    else
                    {
                        SetNextTrigger(id, trigger, callback);
                    }
                }
            };

            timers[id] = new System.Threading.Timer(timerCallback, null, milliSeconds, Timeout.Infinite);
        }
Пример #4
0
 internal SchedulerTask(SchedulerCallback callback, bool isBackground, object userState)
     : this()
 {
     if (callback == null) throw new ArgumentNullException("callback");
     Callback = callback;
     IsBackground = isBackground;
     UserState = userState;
 }
Пример #5
0
 internal SchedulerTask(SchedulerCallback callback, bool isBackground)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     Callback     = callback;
     IsBackground = isBackground;
 }
Пример #6
0
    public IEnumerator handle;          //用于关闭定时器

    public SchedulerData(string _name, float _startInterval = 0, int _runCount = 0, float _timeInterval = 1.0f, SchedulerCallback _callback = null, object _param = null)
    {
        name          = _name;
        startInterval = _startInterval;
        runCount      = _runCount;
        timeInterval  = _timeInterval;
        callback      = _callback;
        param         = _param;
    }
Пример #7
0
 public SchedulerTask(SchedulerCallback callback, object state,
                      TimeSpan delay, bool repeating)
 {
     Callback  = callback;
     State     = state;
     Delay     = delay;
     NextRun   = DateTime.UtcNow.Add(delay);
     Repeating = repeating;
 }
Пример #8
0
 internal SchedulerTask(SchedulerCallback callback, bool isBackground, object userState)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     Callback     = callback;
     IsBackground = isBackground;
     UserState    = userState;
 }
        private void InvokeCallbackAndSetNextTrigger(string id, ITrigger trigger, SchedulerCallback callback)
        {
            callback(id);

            try
            {
                SetNextTrigger(id, trigger, callback);
            }
            catch (NoNextTriggerException)
            {
                // fair enough - no further timer necessary
            }
        }
        public void AddOrUpdate(string id, ITrigger trigger, SchedulerCallback callback)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("Id was null or empty");
            }

            if (timers.ContainsKey(id))
            {
                Remove(id);
            }

            SetNextTrigger(id, trigger, callback);
        }
Пример #11
0
 /// <summary> Creates a new SchedulerTask object to run in the main thread.
 /// Use this if your task is time-sensitive or frequent, and your callback won't take too long to execute. </summary>
 /// <param name="callback"> Method to call when the task is triggered. </param>
 /// <returns> Newly created SchedulerTask object. </returns>
 public static SchedulerTask NewTask(SchedulerCallback callback)
 {
     return new SchedulerTask(callback, false);
 }
Пример #12
0
 /// <summary> Creates a new SchedulerTask object to run in the main thread.
 /// Use this if your task is time-sensitive or frequent, and your callback won't take too long to execute. </summary>
 /// <param name="callback"> Method to call when the task is triggered. </param>
 /// <param name="userState"> Parameter to pass to the method. </param>
 /// <returns> Newly created SchedulerTask object. </returns>
 public static SchedulerTask NewTask(SchedulerCallback callback, object userState)
 {
     return new SchedulerTask(callback, false, userState);
 }
Пример #13
0
 /// <summary> Creates a new SchedulerTask object to run in the background thread.
 /// Use this if your task is not very time-sensitive or frequent, or if your callback is resource-intensive. </summary>
 /// <param name="callback"> Method to call when the task is triggered. </param>
 /// <returns> Newly created SchedulerTask object. </returns>
 public static SchedulerTask NewBackgroundTask(SchedulerCallback callback)
 {
     return new SchedulerTask(callback, true);
 }
Пример #14
0
 /// <summary> Creates a new SchedulerTask object to run in the background thread.
 /// Use this if your task is not very time-sensitive or frequent, or if your callback is resource-intensive. </summary>
 /// <param name="callback"> Method to call when the task is triggered. </param>
 /// <param name="userState"> Parameter to pass to the method. </param>
 /// <returns> Newly created SchedulerTask object. </returns>
 public static SchedulerTask NewBackgroundTask(SchedulerCallback callback, object userState)
 {
     return new SchedulerTask(callback, true, userState);
 }
Пример #15
0
    static int CreateScheduler(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                Scheduler     obj  = (Scheduler)ToLua.CheckObject <Scheduler>(L, 1);
                string        arg0 = ToLua.CheckString(L, 2);
                SchedulerData o    = obj.CreateScheduler(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3)
            {
                Scheduler     obj  = (Scheduler)ToLua.CheckObject <Scheduler>(L, 1);
                string        arg0 = ToLua.CheckString(L, 2);
                float         arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                SchedulerData o    = obj.CreateScheduler(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4)
            {
                Scheduler     obj  = (Scheduler)ToLua.CheckObject <Scheduler>(L, 1);
                string        arg0 = ToLua.CheckString(L, 2);
                float         arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                int           arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                SchedulerData o    = obj.CreateScheduler(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5)
            {
                Scheduler     obj  = (Scheduler)ToLua.CheckObject <Scheduler>(L, 1);
                string        arg0 = ToLua.CheckString(L, 2);
                float         arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                int           arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                float         arg3 = (float)LuaDLL.luaL_checknumber(L, 5);
                SchedulerData o    = obj.CreateScheduler(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 6)
            {
                Scheduler         obj  = (Scheduler)ToLua.CheckObject <Scheduler>(L, 1);
                string            arg0 = ToLua.CheckString(L, 2);
                float             arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                int               arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                float             arg3 = (float)LuaDLL.luaL_checknumber(L, 5);
                SchedulerCallback arg4 = (SchedulerCallback)ToLua.CheckDelegate <SchedulerCallback>(L, 6);
                SchedulerData     o    = obj.CreateScheduler(arg0, arg1, arg2, arg3, arg4);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 7)
            {
                Scheduler         obj  = (Scheduler)ToLua.CheckObject <Scheduler>(L, 1);
                string            arg0 = ToLua.CheckString(L, 2);
                float             arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
                int               arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                float             arg3 = (float)LuaDLL.luaL_checknumber(L, 5);
                SchedulerCallback arg4 = (SchedulerCallback)ToLua.CheckDelegate <SchedulerCallback>(L, 6);
                object            arg5 = ToLua.ToVarObject(L, 7);
                SchedulerData     o    = obj.CreateScheduler(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Scheduler.CreateScheduler"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #16
0
 public static extern void hdScheduleSynchronous([MarshalAs(UnmanagedType.FunctionPtr)] SchedulerCallback callback, IntPtr userData, ushort priority);
Пример #17
0
 /// <summary> Creates a new SchedulerTask object to run in the main thread.
 /// Use this if your task is time-sensitive or frequent, and your callback won't take too long to execute. </summary>
 /// <param name="callback"> Method to call when the task is triggered. </param>
 /// <param name="userState"> Parameter to pass to the method. </param>
 /// <returns> Newly created SchedulerTask object. </returns>
 public static SchedulerTask NewTask(SchedulerCallback callback, object userState)
 {
     return(new SchedulerTask(callback, false, userState));
 }
Пример #18
0
 /// <summary> Creates a new SchedulerTask object to run in the background thread.
 /// Use this if your task is not very time-sensitive or frequent, or if your callback is resource-intensive. </summary>
 /// <param name="callback"> Method to call when the task is triggered. </param>
 /// <param name="userState"> Parameter to pass to the method. </param>
 /// <returns> Newly created SchedulerTask object. </returns>
 public static SchedulerTask NewBackgroundTask(SchedulerCallback callback, object userState)
 {
     return(new SchedulerTask(callback, true, userState));
 }
Пример #19
0
 /// <summary> Queues an action that is asynchronously executed repeatedly, after a certain delay. </summary>
 public SchedulerTask QueueRepeat(SchedulerCallback callback, object state, TimeSpan delay)
 {
     return(EnqueueTask(new SchedulerTask(callback, state, delay, true)));
 }
Пример #20
0
 internal SchedulerTask([NotNull] SchedulerCallback callback, bool isBackground)
     : this()
 {
     Callback     = callback ?? throw new ArgumentNullException(nameof(callback));
     IsBackground = isBackground;
 }
Пример #21
0
 public static SchedulerTask NewTask([NotNull] SchedulerCallback callback, [CanBeNull] object userState)
 {
     return(new SchedulerTask(callback, false, userState));
 }
Пример #22
0
 public static SchedulerTask NewTask([NotNull] SchedulerCallback callback)
 {
     return(new SchedulerTask(callback, false));
 }
Пример #23
0
    public SchedulerData CreateScheduler(string name, float _startInterval = 0, int _runCount = 0, float _timeInterval = 1.0f, SchedulerCallback _callback = null, object _param = null)
    {
        if (string.IsNullOrEmpty(name))
        {
            Debug.LogError("The name is illegal");
            return(null);
        }
        if (schedulers.ContainsKey(name))
        {
            //关闭同名定时器
            Stop(name);
            Debug.LogError("Create Same name Scheduler name = " + name);
        }
        SchedulerData scheduler = new SchedulerData(name, _startInterval, _runCount, _timeInterval, _callback, _param);

        scheduler.handle = scheduler.RunFunction();
        StartCoroutine(scheduler.handle);
        //保存
        schedulers.Add(name, scheduler);
        return(scheduler);
    }
Пример #24
0
 public static SchedulerTask NewBackgroundTask([NotNull] SchedulerCallback callback)
 {
     return(new SchedulerTask(callback, true));
 }
Пример #25
0
 /// <summary> Queues an action that is asynchronously executed one time, as soon as possible. </summary>
 public SchedulerTask QueueOnce(SchedulerCallback callback)
 {
     return(EnqueueTask(new SchedulerTask(callback, null, TimeSpan.Zero, false)));
 }
Пример #26
0
 public static SchedulerTask NewBackgroundTask([NotNull] SchedulerCallback callback, [CanBeNull] object userState)
 {
     return(new SchedulerTask(callback, true, userState));
 }
Пример #27
0
 /// <summary> Queues an action that is asynchronously executed one time, after a certain delay. </summary>
 public SchedulerTask QueueOnce(SchedulerCallback callback, object state, TimeSpan delay)
 {
     return(EnqueueTask(new SchedulerTask(callback, state, delay, false)));
 }