public PeriodicallyScheduledWorkItem(EventLoopScheduler scheduler, TState state, TimeSpan period, Func <TState, TState> action) { _state = state; _period = period; _action = action; _scheduler = scheduler; _next = scheduler._stopwatch.Elapsed + period; Disposable.TrySetSingle(ref _task, scheduler.Schedule(this, _next - scheduler._stopwatch.Elapsed, (_, s) => s.Tick(_))); }
/// <summary> /// Schedules an action to be executed after dueTime. /// </summary> /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> /// <param name="state">State passed to the action to be executed.</param> /// <param name="action">Action to be executed.</param> /// <param name="dueTime">Relative time after which to execute the action.</param> /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception> public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException("action"); } var scheduler = new EventLoopScheduler(_threadFactory); scheduler.ExitIfEmpty = true; return(scheduler.Schedule(state, dueTime, action)); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); if (GetTemplateChild("PART_Browser") is ChromiumWebBrowser browser) { _browser = browser; _browser.FrameLoadEnd += Browser_FrameLoadEnd; _browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged; _browser.ConsoleMessage += Browser_ConsoleMessage; _browser.DownloadHandler = new UnoDownloadHandler(); _browser.ResourceHandlerFactory = _handlerFactory = new UnoResourceHandlerFactory(); RegisterResourceHandlers(); _browser.JavascriptObjectRepository.ResolveObject += (sender, e) => { var repo = e.ObjectRepository; if (e.ObjectName == "UnoDispatch") { repo.Register("UnoDispatch", new UnoDispatch(), options: BindingOptions.DefaultBinder); } }; var loop = new System.Reactive.Concurrency.EventLoopScheduler(); Windows.UI.Core.CoreDispatcher.DispatchOverride = d => loop.Schedule(d); Uno.Foundation.WebAssemblyRuntime.InvokeJSOverride = InvokeJS; } else { throw new InvalidOperationException("Unable to find PART_Browser"); } }