internal SchedulerTask(SchedulerCallback callback, bool isBackground) : this() { if (callback == null) throw new ArgumentNullException("callback"); Callback = callback; IsBackground = isBackground; }
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); }
internal SchedulerTask(SchedulerCallback callback, bool isBackground, object userState) : this() { if (callback == null) throw new ArgumentNullException("callback"); Callback = callback; IsBackground = isBackground; UserState = userState; }
internal SchedulerTask(SchedulerCallback callback, bool isBackground) { if (callback == null) { throw new ArgumentNullException("callback"); } Callback = callback; IsBackground = isBackground; }
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; }
public SchedulerTask(SchedulerCallback callback, object state, TimeSpan delay, bool repeating) { Callback = callback; State = state; Delay = delay; NextRun = DateTime.UtcNow.Add(delay); Repeating = repeating; }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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)); } }
public static extern void hdScheduleSynchronous([MarshalAs(UnmanagedType.FunctionPtr)] SchedulerCallback callback, IntPtr userData, ushort priority);
/// <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)); }
/// <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)); }
/// <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))); }
internal SchedulerTask([NotNull] SchedulerCallback callback, bool isBackground) : this() { Callback = callback ?? throw new ArgumentNullException(nameof(callback)); IsBackground = isBackground; }
public static SchedulerTask NewTask([NotNull] SchedulerCallback callback, [CanBeNull] object userState) { return(new SchedulerTask(callback, false, userState)); }
public static SchedulerTask NewTask([NotNull] SchedulerCallback callback) { return(new SchedulerTask(callback, false)); }
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); }
public static SchedulerTask NewBackgroundTask([NotNull] SchedulerCallback callback) { return(new SchedulerTask(callback, true)); }
/// <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))); }
public static SchedulerTask NewBackgroundTask([NotNull] SchedulerCallback callback, [CanBeNull] object userState) { return(new SchedulerTask(callback, true, userState)); }
/// <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))); }