|
|
|
|
|
|
cancel(); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract int tick { get; } |
|
|
|
public abstract long tick { get; } |
|
|
|
|
|
|
|
public abstract bool isActive { get; } |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
class _Timer : Timer { |
|
|
|
int _tick = 0; |
|
|
|
long _tick = 0; |
|
|
|
int _wakeupTime; |
|
|
|
long _wakeupTime; |
|
|
|
_Timer(ZoneUnaryCallback callback, int wakeupTime, int milliSeconds, bool repeating) { |
|
|
|
_Timer(ZoneUnaryCallback callback, long wakeupTime, int milliSeconds, bool repeating) { |
|
|
|
_callback = callback; |
|
|
|
_wakeupTime = wakeupTime; |
|
|
|
_milliSeconds = milliSeconds; |
|
|
|
|
|
|
milliSeconds = 0; |
|
|
|
} |
|
|
|
|
|
|
|
int now = UIMonoState_timerMillisecondClock(); |
|
|
|
int wakeupTime = (milliSeconds == 0) ? now : (now + 1 + milliSeconds); |
|
|
|
long now = UIMonoState_timerMillisecondClock(); |
|
|
|
long wakeupTime = (milliSeconds == 0) ? now : (now + 1 + milliSeconds); |
|
|
|
|
|
|
|
_Timer timer = new _Timer(callback, wakeupTime, milliSeconds, repeating); |
|
|
|
timer._enqueue(); |
|
|
|
|
|
|
|
|
|
|
public override bool isActive => _callback != null; |
|
|
|
|
|
|
|
public override int tick => _tick; |
|
|
|
public override long tick => _tick; |
|
|
|
|
|
|
|
void _advanceWakeupTime() { |
|
|
|
if (_milliSeconds > 0) { |
|
|
|
|
|
|
void _enqueue() { |
|
|
|
Isolate.ensureExists(); |
|
|
|
|
|
|
|
GCHandle callabackHandle = GCHandle.Alloc(this); |
|
|
|
UIMonoState_postTaskForTime(_postTaskForTime, (IntPtr) callabackHandle, _wakeupTime * MILLI_TO_NANO); |
|
|
|
GCHandle callbackHandle = GCHandle.Alloc(this); |
|
|
|
UIMonoState_postTaskForTime(_postTaskForTime, (IntPtr) callbackHandle, _wakeupTime * MILLI_TO_NANO); |
|
|
|
} |
|
|
|
|
|
|
|
[MonoPInvokeCallback(typeof(UIMonoState_postTaskForTimeCallback))] |
|
|
|
|
|
|
} |
|
|
|
else if (timer._milliSeconds > 0) { |
|
|
|
var ms = timer._milliSeconds; |
|
|
|
int overdue = UIMonoState_timerMillisecondClock() - timer._wakeupTime; |
|
|
|
long overdue = UIMonoState_timerMillisecondClock() - timer._wakeupTime; |
|
|
|
int missedTicks = overdue / ms; |
|
|
|
long missedTicks = overdue / ms; |
|
|
|
timer._wakeupTime += missedTicks * ms; |
|
|
|
timer._tick += missedTicks; |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[DllImport(NativeBindings.dllName)] |
|
|
|
static extern int UIMonoState_timerMillisecondClock(); |
|
|
|
static extern long UIMonoState_timerMillisecondClock(); |
|
|
|
|
|
|
|
delegate void UIMonoState_postTaskForTimeCallback(IntPtr callbackHandle); |
|
|
|
|
|
|
|