Exemple #1
0
        /// <param name="interval">Timeout in Milliseconds</param>
        /// <param name="action">Action<object> to fire when debounced event fires</object></param>
        /// <param name="optParam">optional parameter</param>
        /// <param name="priority">optional priorty for the dispatcher</param>
        /// <param name="dispatcher">optional dispatcher. If not passed or null CurrentDispatcher is used.</param>
        public void Debounce(int interval,
                             Action <object?> action,
                             object?optParam             = null,
                             DispatcherPriority priority = DispatcherPriority.ApplicationIdle,
                             Dispatcher?dispatcher       = null)
        {
            // kill pending timer and pending ticks
            _timer?.Stop();
            _timer = null;

            dispatcher ??= Dispatcher.CurrentDispatcher;

            // timer is recreated for each event and effectively resets the timeout.
            // Action only fires after timeout has fully elapsed without other events firing in between
            _timer = new DispatcherTimer(TimeSpan.FromMilliseconds(interval),
                                         priority,
                                         (s, e) =>
            {
                if (_timer == null)
                {
                    return;
                }

                _timer?.Stop();
                _timer = null;
                action.Invoke(optParam);
            },
                                         dispatcher);

            _timer.Start();
        }
        internal void Clear()
        {
            if (typingTimer != null)
            {
                typingTimer.Stop();
                typingTimer.Tick -= HandleTypingTimerTimeout;
                typingTimer       = null;
            }

            if (activeWpfTextView != null)
            {
                activeWpfTextView.Selection.SelectionChanged -= HandleSelectionChanged;
                activeWpfTextView.TextBuffer.Changed         -= HandleTextBufferChanged;
                activeWpfTextView.LostAggregateFocus         -= HandleTextViewLostFocus;
                activeWpfTextView = null;
            }

            if (activeClassificationFormatMap != null)
            {
                activeClassificationFormatMap.ClassificationFormatMappingChanged -= HandleFormatMappingChanged;
                activeClassificationFormatMap = null;
            }

            if (activeEditorFormatMap != null)
            {
                activeEditorFormatMap.FormatMappingChanged -= HandleFormatMappingChanged;
                activeEditorFormatMap = null;
            }

            activeSyntaxTree = null;
            syntaxVisualizer.Clear();
        }
        internal ValueTask Show(Forms.VisualElement visualElement, SnackBarOptions arguments)
        {
            var snackBarLayout = new SnackBarLayout(arguments);
            var pageControl    = Platform.GetRenderer(visualElement).ContainerElement.Parent;
            var grid           = (Grid)(FindVisualChildByName <Border>(pageControl, "BottomCommandBarArea")?.Parent ?? throw new NotSupportedException("Anchor Not Supported on UWP"));

            var snackBarRow = new RowDefinition()
            {
                Height = GridLength.Auto
            };

            snackBarTimer = new DispatcherTimer {
                Interval = arguments.Duration
            };
            snackBarTimer.Tick += (sender, e) =>
            {
                grid.Children.Remove(snackBarLayout);
                grid.RowDefinitions.Remove(snackBarRow);
                snackBarTimer.Stop();
                arguments.SetResult(false);
            };
            snackBarLayout.OnSnackBarActionExecuted += () =>
            {
                grid.Children.Remove(snackBarLayout);
                grid.RowDefinitions.Remove(snackBarRow);
                snackBarTimer.Stop();
                arguments.SetResult(true);
            };
            snackBarTimer.Start();
            grid.RowDefinitions.Add(snackBarRow);
            grid.Children.Add(snackBarLayout);
            Grid.SetRow(snackBarLayout, grid.RowDefinitions.Count - 1);
            return(default);
        void UpdateScrolling(MouseEventArgs e)
        {
            var mouseLoc = GetLocation(e);

            dispatcherTimerXCoord = mouseLoc.Point.X;
            var scrollDir = GetScrollDirection(mouseLoc, out var interval);

            if (scrollDir is null)
            {
                StopScrolling();
                wpfTextView.Caret.EnsureVisible();
                return;
            }

            if (dispatcherTimer is not null)
            {
                // It resets the timer if we write a new value, even if it's identical to the original value
                if (dispatcherTimer.Interval != interval)
                {
                    dispatcherTimer.Interval = interval;
                }
            }
            else
            {
                dispatcherTimer = new DispatcherTimer(interval, DispatcherPriority.Normal, (s, e2) => OnScroll(scrollDir.Value, dispatcherTimerXCoord), wpfTextView.VisualElement.Dispatcher);
                OnScroll(scrollDir.Value, dispatcherTimerXCoord);
            }
        }
Exemple #5
0
        /// <summary>
        /// Start listening to some changes to system settings.
        /// </summary>
        private void AddSettingsListener()
        {
            if (this.addedSystemEvents)
            {
                return;
            }

            this.addedSystemEvents  = true;
            this.systemSettingTimer = new DispatcherTimer(DispatcherPriority.Render)
            {
                Interval = TimeSpan.FromMilliseconds(500)
            };

            this.systemSettingTimer.Tick += (sender, args) =>
            {
                this.systemSettingTimer.Stop();
                this.SystemSettingChanged?.Invoke(this, EventArgs.Empty);
            };

            SystemEvents.DisplaySettingsChanged += this.SystemEventsOnDisplaySettingsChanged;
            SystemEvents.UserPreferenceChanged  += this.SystemEventsOnDisplaySettingsChanged;

            this.Exit += (sender, args) =>
            {
                SystemEvents.DisplaySettingsChanged -= this.SystemEventsOnDisplaySettingsChanged;
                SystemEvents.UserPreferenceChanged  -= this.SystemEventsOnDisplaySettingsChanged;
            };
        }
Exemple #6
0
 private void StartClock()
 {
     timer = new DispatcherTimer(
         TimeSpan.FromSeconds(1),
         DispatcherPriority.Normal,
         OnTick,
         Dispatcher.CurrentDispatcher);
 }
Exemple #7
0
 protected override void OnAttached()
 {
     base.OnAttached();
     this._dispatcherTimer = new DispatcherTimer(TimeSpan.FromSeconds(1),
                                                 DispatcherPriority.DataBind,
                                                 (sender, args) => this.AssociatedObject.SelectedDateTime = DateTime.Now,
                                                 Dispatcher.CurrentDispatcher);
 }
 private void OnUnloaded(object sender, RoutedEventArgs e)
 {
     if (_refreshTimer != null)
     {
         _refreshTimer.Stop();
         _refreshTimer = null;
     }
 }
Exemple #9
0
 public void Stop()
 {
     if (!(timer is null))
     {
         timer.Stop();
         timer.Tick -= Timer_Tick;
         timer       = null;
     }
 }
Exemple #10
0
        public MainWindow()
        {
            InitializeComponent();

            _timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(1)
            };
            _timer.Tick += TimerOnTick;
        }
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     _stopTimer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Background, (_, _) =>
     {
         _stopTimer?.Stop();
         _isStopping = false;
     }, Dispatcher);
 }
Exemple #12
0
 private void FocusTimer_Tick(object?sender, System.EventArgs e)
 {
     box.Focus();
     if (focusTimer != null)
     {
         focusTimer.Tick -= FocusTimer_Tick;
         focusTimer.Stop();
         focusTimer = null;
     }
 }
Exemple #13
0
 public void Show(UVoicePart part, UNote note, string text)
 {
     viewModel.Part      = part;
     viewModel.Note      = note;
     viewModel.Text      = text;
     viewModel.IsVisible = true;
     box.SelectAll();
     focusTimer       = new DispatcherTimer();
     focusTimer.Tick += FocusTimer_Tick;
     focusTimer.Start();
 }
 // Random thread
 void StopTimer()
 {
     lock (lockObj) {
         if (timer is not null)
         {
             timer.Tick -= Timer_Tick_DbgThread;
             timer.Stop();
             timer = null;
         }
     }
 }
Exemple #15
0
 void StopTimer()
 {
     RemoveFadeOut();
     if (timer is null)
     {
         return;
     }
     timer.Stop();
     timer.Tick -= Timer_Tick;
     timer       = null;
 }
Exemple #16
0
        public CountdownControl()
        {
            _timer = new DispatcherTimer(DispatcherPriority.Render)
            {
                Interval = TimeSpan.FromMilliseconds(20)
            };

            _timer.Tick += TimerFire;

            RegisterToCleanupWhenParentCloses();
        }
Exemple #17
0
 void DoneStep1_NoLock(out bool canNotify)
 {
     if (timer is not null)
     {
         timer.Tick -= Timer_Tick_DbgThread;
         timer.Stop();
         timer = null;
     }
     canNotify            = owner.breakAllHelper is not null;
     owner.breakAllHelper = null;
 }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (_refreshTimer != null)
            {
                return;
            }

            _refreshTimer          = new DispatcherTimer();
            _refreshTimer.Interval = TimeSpan.FromMilliseconds(500.0);
            _refreshTimer.Tick    += this.OnRefreshRefreshTimer_Tick;
            _refreshTimer.Start();
        }
        void Window_Loaded(object sender, RoutedEventArgs e)
        {
            startTime = DateTime.Now;

            if (showTimer)
            {
                timer          = new DispatcherTimer();
                timer.Tick    += Timer_Tick;
                timer.Interval = TimeSpan.FromSeconds(0.9);
                timer.Start();
            }
        }
Exemple #20
0
        public void StartTimer()
        {
            if (_timer is null)
            {
                _timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(1 / 60.0)
                };
                _timer.Tick += AnimationTimerOnTick;
            }

            _timer?.Start();
            IsAnimationRunning = true;
        }
        // Below timer logic ensures that we won't refresh the treeview for each and every
        // character that the user is typing. Instead we wait for a pause in the user's typing
        // that is at least a few hundred milliseconds long before we refresh the treeview.

        private void HandleTextBufferChanged(object sender, EventArgs e)
        {
            if (typingTimer == null)
            {
                typingTimer = new DispatcherTimer
                {
                    Interval = typingTimerTimeout
                };
                typingTimer.Tick += HandleTypingTimerTimeout;
            }

            typingTimer.Stop();
            typingTimer.Start();
        }
Exemple #22
0
        private void StartTimer()
        {
            if (_timer == null)
            {
                _timer       = new DispatcherTimer();
                _timer.Tick += TimerCallback;
            }

            if (!_timer.IsEnabled)
            {
                _timer.Interval = TimeSpan.FromMilliseconds(Delay);
                _timer.Start();
            }
        }
Exemple #23
0
 void StartTimerIfNeeded()
 {
     if (IsMouseWithinControls)
     {
         return;
     }
     if (timer is not null)
     {
         return;
     }
     timer          = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher);
     timer.Tick    += Timer_Tick;
     timer.Interval = TimeSpan.FromSeconds(1);
     timer.Start();
 }
Exemple #24
0
        private void StartTimer()
        {
            if (_repeatTimer == null)
            {
                _repeatTimer       = new DispatcherTimer();
                _repeatTimer.Tick += RepeatTimerOnTick;
            }

            if (_repeatTimer.IsEnabled)
            {
                return;
            }

            _repeatTimer.Interval = TimeSpan.FromMilliseconds(Delay);
            _repeatTimer.Start();
        }
Exemple #25
0
        private static void InitTimer()
        {
            if (queuePullTimer is null)
            {
                queuePullTimer = new DispatcherTimer(DispatcherPriority.Background)
                {
                    Interval = TimeSpan.FromSeconds(1.5d)
                };

                queuePullTimer.Tick += QueuePullTimer_Tick;
            }

            if (!queuePullTimer.IsEnabled)
            {
                queuePullTimer.Start();
            }
        }
Exemple #26
0
        public void InitTimer()
        {
            if (Timer is not null)
            {
                Timer.Stop();
            }
            Timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(UpdateInterval)
            };
            Timer.Tick += async(sender, e) =>
            {
                await TimerTickAsync();
            };

            Timer.Start();
        }
Exemple #27
0
    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        _mediaOut = new WaveOutEvent();
        _mediaOut.PlaybackStopped += Player_PlaybackStopped;

        _posTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(PositionRefreshMilliseconds), DispatcherPriority.Render, Timer_PositionChanged, Dispatcher)
        {
            IsEnabled = false
        };

        _mediaOut.Volume = (float)base.Volume / 100;

        if (!string.IsNullOrEmpty(Source) && !_initLoaded)
        {
            LoadMedia();
        }
    }
        public SubtitleProvider(string?srtFilePath, TimeSpan videoPlayHead)
        {
            if (!string.IsNullOrEmpty(srtFilePath))
            {
                _file = new SubtitleFile(srtFilePath);

                if (_file.Count > 0)
                {
                    _timer       = new DispatcherTimer();
                    _timer.Tick += HandleTimerTick;

                    _videoStartTime = DateTime.UtcNow - videoPlayHead;

                    OnSubtitleEvent(SubtitleStatus.NotShowing, null);

                    QueueNextSubtitle();
                }
            }
        }
        /// <summary>
        /// When any filter condition has changed restart the evaluation timer to defer
        /// the evaluation until the user has stopped typing.
        /// </summary>
        internal void OnFilterChanged()
        {
            if (!_isFilteringEnabled)
            {
                return;
            }

            // Ensure that no cell is in editing state, this would cause an exception when trying to change the filter!
            DataGrid.CommitEdit(); // Commit cell
            DataGrid.CommitEdit(); // Commit row

            if (_deferFilterEvaluationTimer == null)
            {
                var throttleDelay = DataGrid.GetFilterEvaluationDelay();
                _deferFilterEvaluationTimer = new DispatcherTimer(throttleDelay, DispatcherPriority.Input, (_, _) => EvaluateFilter(), Dispatcher.CurrentDispatcher);
            }

            _deferFilterEvaluationTimer.Restart();
        }
Exemple #30
0
    protected override void OnInitialized()
    {
        base.OnInitialized();

        if (!Design.IsDesignMode)
        {
            BassDevice.Instance.Init();

            this.FindLogicalAncestorOfType <TopLevel>() !.Closed += (_, _) => Dispose();

            _posTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(PositionRefreshMilliseconds),
                                            DispatcherPriority.Render, Timer_PositionChanged);

            if (!string.IsNullOrEmpty(Source) && !_initLoaded)
            {
                LoadMedia();
            }
        }
    }