/// <inheritdoc/> public void Start() { if (!_running && _renderLoop != null) { _renderLoop.Add(this); _running = true; } }
/// <inheritdoc/> public void Start() { lock (_startStopLock) { if (!_running && _renderLoop != null) { _renderLoop.Add(this); _running = true; } } }
public PlotSampleView() { renderLoop = AvaloniaLocator.Current.GetService <IRenderLoop>(); this.WhenActivated(disposables => { SafeViewModel(vm => { stopWatchRenderLoopTask = new StopWatchRenderLoopTask().DisposeWith(disposables); renderLoop.Add(stopWatchRenderLoopTask); Disposable.Create(() => renderLoop.Remove(stopWatchRenderLoopTask)).DisposeWith(disposables); this.WhenAnyValue(x => x.ViewModel.IsPlotEnable) .Subscribe(x => { if (x)// plot enable, start monitor ui update time { plotEnableDisposables = new CompositeDisposable().DisposeWith(disposables); this.WhenAnyValue(x => x.stopWatchRenderLoopTask.UiUpdateElapsedMilliseconds) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => { #if DEBUG try { FpsBlock.Text = (1000 / vm.InvalidatePlotPostedElapsedMilliseconds).ToString("D2"); } catch (DivideByZeroException) { } catch (Exception) { throw; } #endif //Set MinPlotUpdateInterval higher if ui take long time to update vm.MinPlotUpdateIntervalMilliseconds = (int)( stopWatchRenderLoopTask.UiUpdateElapsedMilliseconds + (stopWatchRenderLoopTask.UiUpdateElapsedMilliseconds - vm.InvalidatePlotPostedElapsedMilliseconds) * 0.5); }) .DisposeWith(plotEnableDisposables); stopWatchRenderLoopTask.NeedsUpdate = true; } else { // plot disable, stop monitor ui update time stopWatchRenderLoopTask.NeedsUpdate = false; plotEnableDisposables?.Dispose(); } }).DisposeWith(disposables); }); }); InitializeComponent(); }