private void OnRendering(object sender, TimeSpan e) { if (_frameEventArgs == null) { _mutableReference = _frameEventArgs = new FrameEventArgs(e); } else { _mutableReference.Update(e); } DispatchUICallback?.Invoke(this, _frameEventArgs); NativeAnimatedCallback?.Invoke(this, _frameEventArgs); JavaScriptEventsCallback?.Invoke(this, _frameEventArgs); IdleCallback?.Invoke(this, _frameEventArgs); lock (_gate) { if (_callbackKeys.Count == 0) { if (++_currentInactiveCount >= InactiveFrameCount) { Unsubscribe(); } } else { _currentInactiveCount = 0; } } }
public static void RunOnIdle(IdleCallback callBack, object state = null, double delayInSeconds = 0) { if (!timer.IsRunning) { timer.Start(); } using (TimedLock.Lock(functionsToCallOnIdle, "PendingUiEvents AddAction()")) { functionsToCallOnIdle.Add(new CallBackAndState(callBack, state, timer.ElapsedMilliseconds + (int)(delayInSeconds * 1000))); } }
private void OnRendering(object sender, object e) { var renderingArgs = e as RenderingEventArgs; if (renderingArgs == null) { throw new InvalidOperationException("Expected rendering event arguments."); } var renderingTime = renderingArgs.RenderingTime; if (_frameEventArgs == null) { _mutableReference = _frameEventArgs = new FrameEventArgs(renderingTime); } else { _mutableReference.Update(renderingTime); } DispatchUICallback?.Invoke(sender, _frameEventArgs); NativeAnimatedCallback?.Invoke(sender, _frameEventArgs); JavaScriptEventsCallback?.Invoke(sender, _frameEventArgs); IdleCallback?.Invoke(sender, _frameEventArgs); lock (_gate) { if (_callbackKeys.Count == 0) { if (++_currentInactiveCount >= InactiveFrameCount) { CompositionTarget.Rendering -= OnRendering; _isSubscribed = false; } } else { _currentInactiveCount = 0; } } }
public static void RunOnIdle(IdleCallback callBack, double delayInSeconds) { RunOnIdle(callBack, null, delayInSeconds); }
internal CallBackAndState(IdleCallback idleCallBack, object stateInfo, long absoluteMillisecondsToRunAt) { this.idleCallBack = idleCallBack; this.stateInfo = stateInfo; this.absoluteMillisecondsToRunAt = absoluteMillisecondsToRunAt; }
/// <summary> /// Sets the global idle callback. /// </summary> /// <param name="func"> /// The new idle callback function. See <see cref="IdleCallback" />. /// </param> /// <remarks> /// <para> /// <b>glutIdleFunc</b> sets the global idle callback to be func so a GLUT program /// can perform background processing tasks or continuous animation when window /// system events are not being received. If enabled, the idle callback is /// continuously called when events are not being received. The callback routine /// has no parameters. The current window and current menu will not be changed /// before the idle callback. Programs with multiple windows and/or menus should /// explicitly set the current window and/or current menu and not rely on its /// current setting. /// </para> /// <para> /// The amount of computation and rendering done in an idle callback should be /// minimized to avoid affecting the program's interactive response. In general, /// not more than a single frame of rendering should be done in an idle callback. /// </para> /// <para> /// Passing <c>null</c> to <b>glutIdleFunc</b> disables the generation of the idle /// callback. /// </para> /// </remarks> /// <seealso cref="IdleCallback" /> // GLUTAPI void APIENTRY glutIdleFunc(void (GLUTCALLBACK *func)(void)); public static void glutIdleFunc([In] IdleCallback func) { idleCallback = func; __glutIdleFunc(idleCallback); }
private static extern void __glutIdleFunc(IdleCallback func);