override public void oneLoop() { int timeIntervalToNextLoop = 0; lock (_excutableList) { if (_excutableList.Count != 0) { traversalAndExcute(true); } if (_excutableList.Count > 0) { OnTimeExecution execution = (OnTimeExecution)_excutableList[0]; if (execution != null) { timeIntervalToNextLoop = (int)(execution.when() - ApplicationEX.GetCurrnSystemMillisecond()); } } maualResetEvent.Reset(); } if (timeIntervalToNextLoop > 0) { maualResetEvent.WaitOne(timeIntervalToNextLoop); } else { maualResetEvent.WaitOne(); } }
//异步执行func,执行结束把他的返回值作为callback的参数回调回来// static public Operation DoFuncOnMainThread <R>(Func <R> func, long delay = 0, VFunc1 <R> callback = null) { Invocation <R, Null, Null> inv = new Invocation <R, Null, Null> (func, 0, null, true); Invocation <Null, R, Null> cbInv = callback == null ? null : new Invocation <Null, R, Null> (callback, 1, null); Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv); MainThread.Instance.addExcutable(operation); return(operation); }
static public Operation DoFuncOnThread <R>(LoopThread loopThrad, Func <R> func, VFunc1 <R> callback = null, bool callbackOnMainThread = true, long delay = 0) { Invocation <R, Null, Null> inv = new Invocation <R, Null, Null> (func, 0, null, true); Invocation <Null, R, Null> cbInv = callback == null ? null : new Invocation <Null, R, Null> (callback, 1); Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv, callbackOnMainThread); loopThrad.addExecution(operation); return(operation); }
static public Operation DoFuncOnMainThread <R, Arg1, Arg2>(Func2 <R, Arg1, Arg2> func, Arg1 arg1, Arg2 arg2, long delay = 0, VFunc1 <R> callback = null) { object[] args = { arg1, arg2 }; Invocation <R, Arg1, Arg2> inv = new Invocation <R, Arg1, Arg2> (func, 2, args, true); Invocation <Null, R, Null> cbInv = callback == null ? null : new Invocation <Null, R, Null> (callback, 1, null); Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv); MainThread.Instance.addExcutable(operation); return(operation); }
static public Operation DoVoidFuncOnMainThread <Arg1, Arg2>(VFunc2 <Arg1, Arg2> func, Arg1 arg1, Arg2 arg2, long delay = 0, VFunc cb = null) { object[] argList = { arg1, arg2 }; Invocation <Null, Arg1, Arg2> invocation = new Invocation <Null, Arg1, Arg2> (func, 2, argList); Invocation <Null, Null, Null> cbInvo = cb == null ? null : new Invocation <Null, Null, Null> (cb, 0, null); Operation operation = new Operation(invocation, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInvo); MainThread.Instance.addExcutable(operation); return(operation); }
static public Operation DoVoidFuncOnMainThread(VFunc func, long delay = 0, VFunc cb = null) { Invocation <Null, Null, Null> invocation = new Invocation <Null, Null, Null> (func, 0, null); Invocation <Null, Null, Null> cbInvo = cb == null ? null : new Invocation <Null, Null, Null> (cb, 0, null); Operation operation = new Operation(invocation, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInvo); //MainThread.Instance.addExcutable (operation); DoOperation(operation); return(operation); }
static public Operation DoFuncOnThread <R, Arg1, Arg2>(LoopThread loopThrad, Func2 <R, Arg1, Arg2> func, Arg1 arg1, Arg2 arg2, VFunc1 <R> callback = null, bool callbackOnMainThread = true, long delay = 0) { object[] args = { arg1, arg2 }; Invocation <R, Arg1, Arg2> inv = new Invocation <R, Arg1, Arg2> (func, 2, args, true); Invocation <Null, R, Null> cbInv = callback == null ? null : new Invocation <Null, R, Null> (callback, 1); Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv, callbackOnMainThread); loopThrad.addExecution(operation); return(operation); }
static public Operation DoVoidFuncOnThread <Arg>(LoopThread loopThrad, VFunc1 <Arg> func, Arg arg, VFunc callback = null, bool callbackOnMainThread = true, long delay = 0) { object[] args = { arg }; Invocation <Null, Arg, Null> inv = new Invocation <Null, Arg, Null> (func, 1, args); Invocation <Null, Null, Null> cbInv = callback == null ? null : new Invocation <Null, Null, Null> (callback); Operation operation = new Operation(inv, ApplicationEX.GetCurrnSystemMillisecond() + delay, cbInv, callbackOnMainThread); loopThrad.addExecution(operation); return(operation); }
bool IExcutable.canExcute() { return(when() - ApplicationEX.GetCurrnSystemMillisecond() <= 0); }