public void OnDeviceStateChanged(string deviceId, DeviceState newState) { if (string.IsNullOrWhiteSpace(deviceId)) { return; } var device = _enumerator.GetDevice(deviceId); _dispatcher.Debounce(300, (o) => DevicesChanged(device, newState)); }
public override void AddedToDocument(GH_Document document) { base.AddedToDocument(document); // This would set the converter already. Params.ParameterChanged += (sender, args) => { if (args.ParameterSide != GH_ParameterSide.Input || args.ParameterIndex == 0) { return; } switch (args.OriginalArguments.Type) { case GH_ObjectEventType.NickName: // This means the user is typing characters, debounce until it stops for 400ms before expiring the solution. // Prevents UI from locking too soon while writing new names for inputs. args.Parameter.Name = args.Parameter.NickName; nicknameChangeDebounce.Debounce(400, (e) => ExpireSolution(true)); break; case GH_ObjectEventType.NickNameAccepted: args.Parameter.Name = args.Parameter.NickName; ExpireSolution(true); break; } }; }
private void OnTextInput() { if (!_skipUpdate) { if (!_updateSelectedValue()) { var key = _textBox.Text; if (string.IsNullOrEmpty(key)) { return; } if (_cache.ContainsKey(key)) { _updateDataList(_cache[key]); } else { _debounceDispatcher.Debounce(() => { _loadingDiv.SetVisibility(true); _queryOptions(_textBox.Text).ContinueWith(e => { _cache[key] = e.Result; _loadingDiv.SetVisibility(false); _updateDataList(e.Result); }); }); } } } }
static void Main(string[] args) { string str = ""; bool stop = false; var debounceDispatcher = new DebounceDispatcher(1000); do { var key = Console.ReadKey(true); //trigger when to stop and exit if (key.Key == ConsoleKey.Escape) { stop = true; } str += key.KeyChar; //every keypress iteration call dispatcher but the Action will be invoked only after stop pressing and waiting 1000 milliseconds debounceDispatcher.Debounce(() => { Console.WriteLine($"{str} - {DateTime.UtcNow.ToString("hh:mm:ss.fff")}"); str = ""; }); }while (!stop); //wait trigger to stop and exit }
/// <summary> /// If the file open in the active tab has changed try to /// either update the document if not dirty, otherwise /// do nothing and wait for OnActivate to trigger a comparison. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void FileWatcher_Changed(object sender, FileSystemEventArgs e) { // Debug.WriteLine("FileWatcher: " + e.FullPath); debounce.Debounce(200, (p) => { // Debug.WriteLine("FileWatcher Debounce: " + e.FullPath); var tab = mmApp.Model.Window.TabControl.SelectedItem as TabItem; var editor = tab?.Tag as MarkdownDocumentEditor; var document = editor?.MarkdownDocument; if (document == null) { return; } // if the file was saved in the last second - don't update because // the change event most likely is from the save op // Note: this can include auto-save operations if (document.LastSaveTime > DateTime.UtcNow.AddMilliseconds(-1000) || document.IsDirty || !document.Filename.Equals(e.FullPath, StringComparison.InvariantCultureIgnoreCase)) { return; } // load the document if (!document.Load(document.Filename)) { return; } // Debug.WriteLine("FileWatcher Updating: " + e.FullPath); // if the file was saved in the last second - don't update because // the change event most likely is from the save op // Note: this can include auto-save operations if (document.LastSaveTime > DateTime.UtcNow.AddMilliseconds(-1000)) { return; } try { int scroll = editor.GetScrollPosition(); editor.SetMarkdown(document.CurrentText); editor.AceEditor?.UpdateDocumentStats(); if (scroll > -1) { editor.SetScrollPosition(scroll); } } catch { } mmApp.Model.Window.PreviewBrowser?.PreviewMarkdown(editor, keepScrollPosition: true); //Debug.WriteLine("FileWatcher Updating DONE: " + e.FullPath); }, null, DispatcherPriority.Normal, mmApp.Model.Window.Dispatcher); }
private void PolyLine_OnMouseOut(object sender, MouseEventArgs <BingMapPolyline> e) { MouseOver = false; MouseOut = true; outDispatcher.Debounce(2000, () => { MouseOut = false; StateHasChanged(); }); StateHasChanged(); }
private void SearchBoxChanged(object sender, TextChangedEventArgs e) { debounceTimer.Debounce(100, _ => { var sortedItems = inventorySearcher.Search(searchBox.Text); itemList.SetItems(sortedItems); }); }
private async Task Page(BetterPaginatorPageEvent pageEvent) { await debounceTimer.Debounce <BetterPaginatorPageEvent>( DebounceInterval, async data => { await InvokeAsync(async() => await OnPage.InvokeAsync(data)); }, pageEvent); }
private void gridRequestsResponses_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) { _removeTimer.Debounce(100, new Action <object>((x) => { if (string.IsNullOrEmpty(WorkspacePath)) { return; } File.WriteAllText(WorkspacePath + ".json", JsonConvert.SerializeObject(Workspace)); })); }
private void PaddingNumberBox_ValueChanged(Microsoft.UI.Xaml.Controls.NumberBox sender, Microsoft.UI.Xaml.Controls.NumberBoxValueChangedEventArgs args) { debounceDispatcher.Debounce(() => { DispatcherHelper.CheckBeginInvokeOnUI(async() => { ValueSet message = new ValueSet(); message.Add("padding_set", args.NewValue); await App.Connection.SendMessageAsync(message); }); }); }
private void NameTextBoxChanged(object sender, TextChangedEventArgs e) { debounceTimer.Debounce(500, _ => { if (loadout.Name == nameTextBox.Text) { return; } loadout.Name = nameTextBox.Text; SaveLoadoutChanges(); }); }
private AppModel() { _notificationManager = new NotificationManager(this); _deviceCyclerManager = new DeviceCyclerManager(); MMNotificationClient.Instance.DefaultDeviceChanged += (sender, @event) => { _dispatcher.Debounce(250, o => { Log.Information(@"[WINAPI] Default device changed to {device}:{role}", @event.Device, @event.Role); DefaultDeviceChanged?.Invoke(sender, @event); }); }; }
private AppModel() { _notificationManager = new NotificationManager(this); _deviceCyclerManager = new DeviceCyclerManager(); MMNotificationClient.Instance.DefaultDeviceChanged += (sender, @event) => { _dispatcher.Debounce(TimeSpan.FromMilliseconds(200), defaultDeviceChanged => { Log.Information(@"[WINAPI] Default device changed to {device}:{role}", @event.Device, @event.Role); defaultDeviceChanged?.Invoke(sender, @event); }, DefaultDeviceChanged); }; _microphoneMuteToggler = new MicrophoneMuteToggler(AudioSwitcher.Instance, _notificationManager); }
private void MainBrowser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e) { Dispatcher.Invoke(() => { try { urlTextbox.Text = MainBrowser.Address; titleLabel.Content = MainBrowser.Title; titleLabel.ToolTip = MainBrowser.Title; if (MainBrowser == null) { } else if (MainBrowser.Title == string.Empty) { } else if (MainBrowser.Address.StartsWith("data")) { } else { // debounce creation of history for 2s, so that it doesn't log history for unnecessary redirects debounceDispatcher.Debounce(2000, _ => { History.CreateHistory(new History { Url = MainBrowser.Address, Title = MainBrowser.Title, Timestamp = DateTime.Now }); }); } if (IsUrlYoutubeVideo(MainBrowser.Address)) { YoutubeModeMenuItem.IsEnabled = true; } else { YoutubeModeMenuItem.IsEnabled = false; } } catch (Exception exc) { //MessageBox.Show(exc.ToString()); } }); }
// This is too slow so require SPACE to refresh on key navigation private void TreeViewItem_KeyUp(object sender, KeyEventArgs e) { keyUpDispatcher.Debounce(500, (p) => { var ev = p as KeyEventArgs; if (ev.Key == Key.Up || ev.Key == Key.Down) { var tvi = e.OriginalSource as TreeViewItem; if (tvi == null) { return; } HandleSelection(); } }, e, DispatcherPriority.ApplicationIdle, Dispatcher); }
public void RefreshItems() { debounceDispatcher.Debounce(() => { var totalPaths = Paths; totalPaths.ForEach((i) => { Debug.Log("ddddd+++++" + i); }); var totalItems = GetTotalItem(); totalItems.ForEach((item) => { var resItem = item.GetComponent <ResourceItem>(); var resInfo = resItem.ResInfo; resInfo.Tag = totalPaths.Contains(resInfo.FileName) ? ResourceTag.CocosStudio : ResourceTag.Default; resItem.SetUI(); }); }); }
public override void AddedToDocument(GH_Document document) { if (readFailed) { return; } if (!UserSetSchemaTag) { UseSchemaTag = SpeckleGHSettings.UseSchemaTag; } if (SelectedConstructor != null) { base.AddedToDocument(document); if (Grasshopper.Instances.ActiveCanvas.Document != null) { var otherSchemaBuilders = Grasshopper.Instances.ActiveCanvas.Document.FindObjects(new List <string>() { Name }, 10000); foreach (var comp in otherSchemaBuilders) { if (comp is CreateSchemaObject scb) { if (scb.Seed == Seed) { Seed = GenerateSeed(); break; } } } } } if (Params.Input.Count == 0) { SetupComponent(SelectedConstructor); } ((SpeckleBaseParam)Params.Output[0]).UseSchemaTag = UseSchemaTag; (Params.Output[0] as SpeckleBaseParam).ExpirePreview(true); Params.ParameterChanged += (sender, args) => { if (args.ParameterSide != GH_ParameterSide.Input) { return; } switch (args.OriginalArguments.Type) { case GH_ObjectEventType.NickName: // This means the user is typing characters, debounce until it stops for 400ms before expiring the solution. // Prevents UI from locking too soon while writing new names for inputs. args.Parameter.Name = args.Parameter.NickName; nicknameChangeDebounce.Debounce(400, (e) => ExpireSolution(true)); break; case GH_ObjectEventType.NickNameAccepted: args.Parameter.Name = args.Parameter.NickName; ExpireSolution(true); break; } }; base.AddedToDocument(document); }
/// <summary> /// If the file open in the active tab has changed try to /// either update the document if not dirty, otherwise /// do nothing and wait for save operation to trigger /// comparison or choosing which file to pick (in SaveDocument()) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void FileWatcher_Changed(object sender, FileSystemEventArgs e) { debounce.Debounce(200, (objPath) => { string fullPath = objPath as string; // Get the current editor and document var tab = mmApp.Model.Window.TabControl.SelectedItem as TabItem; var editor = tab?.Tag as MarkdownDocumentEditor; var document = editor?.MarkdownDocument; bool isActiveTabFile = document != null && document.Filename.Equals(fullPath, StringComparison.InvariantCultureIgnoreCase); if (!isActiveTabFile) { tab = mmApp.Model.Window.GetTabFromFilename(fullPath); editor = tab?.Tag as MarkdownDocumentEditor; document = editor?.MarkdownDocument; } if (document == null) { return; } // Only work changes on the active tab // if the file was saved in the last second - don't update because // the change event most likely is from the save op // Note: this can include auto-save operations if (document.LastSaveTime > DateTime.UtcNow.AddMilliseconds(-1000) || document.IsDirty) { return; } // Otherwise reload from disk and refresh editor and preview // load the document if (!document.Load(document.Filename)) { return; } try { int scroll = editor.GetScrollPosition(); editor.SetMarkdown(document.CurrentText, keepUndoBuffer: true); if (isActiveTabFile) { editor.AceEditor?.UpdateDocumentStats(); } if (scroll > -1) { editor.SetScrollPosition(scroll); } } catch { } if (isActiveTabFile && document.ToString() != MarkdownDocument.PREVIEW_HTML_FILENAME) { mmApp.Model.Window.PreviewBrowser?.PreviewMarkdown(editor, keepScrollPosition: true); } }, e.FullPath, DispatcherPriority.Normal, mmApp.Model.Window.Dispatcher); }
private AppModel() { RegisterForRestart(); RegisterRecovery(); _notificationManager = new NotificationManager(this); _deviceCyclerManager = new DeviceCyclerManager(); MMNotificationClient.Instance.DefaultDeviceChanged += (sender, @event) => { _dispatcher.Debounce(250, o => { DefaultDeviceChanged?.Invoke(sender, @event); }); }; }
public override void AddedToDocument(GH_Document document) { if (readFailed) return; // To ensure conversion strategy does not change, we record if the user has modified this schema tag and will keep it as is. // If not, schemaTag will be synchronised with the default value every time the document opens. if (!UserSetSchemaTag) UseSchemaTag = SpeckleGHSettings.UseSchemaTag; if (SelectedConstructor != null) { base.AddedToDocument(document); if (Grasshopper.Instances.ActiveCanvas.Document == null) return; var otherSchemaBuilders = Grasshopper.Instances.ActiveCanvas.Document.FindObjects(new List<string>() { Name }, 10000); foreach (var comp in otherSchemaBuilders) { if (!(comp is CreateSchemaObject scb)) continue; if (scb.Seed != Seed) continue; Seed = GenerateSeed(); break; } (Params.Output[0] as SpeckleBaseParam).UseSchemaTag = UseSchemaTag; (Params.Output[0] as SpeckleBaseParam).ExpirePreview(true); return; } _document = document; var dialog = new CreateSchemaObjectDialog(); dialog.Owner = Grasshopper.Instances.EtoDocumentEditor; var mouse = GH_Canvas.MousePosition; dialog.Location = new Eto.Drawing.Point((int)((mouse.X - 150) / dialog.Screen.LogicalPixelSize), (int)((mouse.Y - 150) / dialog.Screen.LogicalPixelSize)); //approx the dialog half-size dialog.ShowModal(); if (dialog.HasResult) { base.AddedToDocument(document); SwitchConstructor(dialog.model.SelectedItem.Tag as ConstructorInfo); Params.ParameterChanged += (sender, args) => { if (args.ParameterSide != GH_ParameterSide.Input) return; switch (args.OriginalArguments.Type) { case GH_ObjectEventType.NickName: // This means the user is typing characters, debounce until it stops for 400ms before expiring the solution. // Prevents UI from locking too soon while writing new names for inputs. args.Parameter.Name = args.Parameter.NickName; nicknameChangeDebounce.Debounce(400, (e) => ExpireSolution(true)); break; case GH_ObjectEventType.NickNameAccepted: args.Parameter.Name = args.Parameter.NickName; ExpireSolution(true); break; } }; } else { document.RemoveObject(Attributes, true); } }
private void Form_AmethystSystrayHotKey(object sender, int e) { if (e == 0x11) //space bar { HMONITOR currentMonitor = User32.MonitorFromPoint(Control.MousePosition, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); VirtualDesktop currentDesktop = VirtualDesktop.Current; Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(currentDesktop, currentMonitor); DWM.RotateLayoutClockwise(currentPair); DWM.Draw(currentPair); DWM.SaveLayouts(); } if (e == 0x12) //enter { HWND selectedWindow = User32.GetForegroundWindow(); HMONITOR currentMonitor = User32.MonitorFromWindow(selectedWindow, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); DesktopWindow selected = DWM.GetWindowByHandlers(selectedWindow, currentMonitor, VirtualDesktop.Current); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.SetMainWindow(currentPair, selected); DWM.Draw(currentPair); } if (e == 0x15) // j { HWND selectedWindow = User32.GetForegroundWindow(); HMONITOR currentMonitor = User32.MonitorFromWindow(selectedWindow, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); DesktopWindow selected = DWM.GetWindowByHandlers(selectedWindow, currentMonitor, VirtualDesktop.Current); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.RotateFocusedWindowClockwise(currentPair, selected); DWM.Draw(currentPair); } if (e == 0x14) // k { HWND selectedWindow = User32.GetForegroundWindow(); HMONITOR currentMonitor = User32.MonitorFromWindow(selectedWindow, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); DesktopWindow selected = DWM.GetWindowByHandlers(selectedWindow, currentMonitor, VirtualDesktop.Current); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.RotateFocusedWindowCounterClockwise(currentPair, selected); DWM.Draw(currentPair); } if (e == 0x13) // l { HWND selectedWindow = User32.GetForegroundWindow(); HMONITOR currentMonitor = User32.MonitorFromWindow(selectedWindow, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); DesktopWindow selected = DWM.GetWindowByHandlers(selectedWindow, currentMonitor, VirtualDesktop.Current); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.MoveWindowClockwise(currentPair, selected); DWM.Draw(currentPair); } if (e == 0x16) //h { HWND selectedWindow = User32.GetForegroundWindow(); HMONITOR currentMonitor = User32.MonitorFromWindow(selectedWindow, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); DesktopWindow selected = DWM.GetWindowByHandlers(selectedWindow, currentMonitor, VirtualDesktop.Current); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.MoveWindowCounterClockwise(currentPair, selected); DWM.Draw(currentPair); } if (e == 0x17) //z { DWM.ClearWindows(); DWM.GetWindows(); DWM.Draw(); } if (e == 0x21) //space bar { HMONITOR currentMonitor = User32.MonitorFromPoint(Control.MousePosition, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); VirtualDesktop currentDesktop = VirtualDesktop.Current; Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(currentDesktop, currentMonitor); DWM.RotateLayoutCounterClockwise(currentPair); DWM.Draw(currentPair); DWM.SaveLayouts(); } if (e == 0x22) //h { debounceDispatcher.Debounce(() => { HMONITOR currentMonitor = User32.MonitorFromPoint(Control.MousePosition, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.ExpandMainPane(currentPair); DWM.Draw(currentPair); }); } if (e == 0x23) //l { debounceDispatcher.Debounce(() => { HMONITOR currentMonitor = User32.MonitorFromPoint(Control.MousePosition, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(VirtualDesktop.Current, currentMonitor); DWM.ShrinkMainPane(currentPair); DWM.Draw(currentPair); }); } if (e == 0x24) //j { HWND selectedWindow = User32.GetForegroundWindow(); DesktopWindow selected = DWM.FindWindow(selectedWindow); DWM.MoveWindowPreviousScreen(selected); DWM.Draw(); } if (e == 0x25) //k { HWND selectedWindow = User32.GetForegroundWindow(); DesktopWindow selected = DWM.FindWindow(selectedWindow); DWM.MoveWindowNextScreen(selected); DWM.Draw(); } if (e == 0x21) //l { HMONITOR currentMonitor = User32.MonitorFromPoint(Control.MousePosition, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); VirtualDesktop currentDesktop = VirtualDesktop.Current; Pair <VirtualDesktop, HMONITOR> currentPair = new Pair <VirtualDesktop, HMONITOR>(currentDesktop, currentMonitor); DWM.RotateLayoutCounterClockwise(currentPair); DWM.Draw(currentPair); DWM.SaveLayouts(); } if (e == 0x26) //right { debounceDispatcher.Debounce(() => { HWND selectedWindow = User32.GetForegroundWindow(); DesktopWindow selected = DWM.FindWindow(selectedWindow); DWM.MoveWindowNextVirtualDesktop(selected); DWM.Draw(); }); } if (e == 0x27) //right { debounceDispatcher.Debounce(() => { HWND selectedWindow = User32.GetForegroundWindow(); DesktopWindow selected = DWM.FindWindow(selectedWindow); DWM.MoveWindowPreviousVirtualDesktop(selected); DWM.Draw(); }); } if (e == 0x1 || e == 0x2 || e == 0x3 || e == 0x4 || e == 0x5) //1,2,3,4,5 { debounceDispatcher.Debounce(() => { HWND selectedWindow = User32.GetForegroundWindow(); DesktopWindow selected = DWM.FindWindow(selectedWindow); DWM.MoveWindowSpecificVirtualDesktop(selected, e - 1); DWM.Draw(); }); } }
private void PolyLine_OnMouseDown(object sender, MouseEventArgs <BingMapPolyline> e) { MouseDown = true; downDispatcher.Debounce(2000, () => { MouseDown = false; StateHasChanged(); }); StateHasChanged(); }
private void Polygon_OnClick(object sender, MouseEventArgs <BingMapPolygon> e) { Click = true; clickDispatcher.Debounce(2000, (o) => { Click = false; StateHasChanged(); }); StateHasChanged(); }
// debounce user input otherwise for 300ms, it'll slow down the UI and make the app unresponsive private void SearchHistoryTextBox_TextChanged(object sender, TextChangedEventArgs e) => debounceDispatcher.Debounce(300, _ => LoadHistory(SearchHistoryTextBox.Text));
private void Redraw() { _redrawDispatcher.Debounce(100, _ => _redraw = true, disp: _canvasView.Dispatcher); }
private void DeviceChanged(object sender, DeviceChangedEventBase e) { _dispatcher.Debounce(300, async(o) => await Refresh()); }
private void DeviceChanged(object sender, DeviceChangedEventBase e) { _dispatcher.Debounce(150, (o) => Refresh()); }
private void PolyLine_OnDoubleClick(object sender, MouseEventArgs <BingMapPolyline> e) { DoubleClick = true; doubleClickDispatcher.Debounce(2000, () => { DoubleClick = false; StateHasChanged(); }); StateHasChanged(); }
private void Polygon_OnMouseUp(object sender, MouseEventArgs <BingMapPolygon> e) { MouseUp = true; upDispatcher.Debounce(2000, (o) => { MouseUp = false; StateHasChanged(); }); StateHasChanged(); }
private void ScheduleDataChange(TimeSpan withinTime) { changeDebounce.Debounce( withinTime, TriggerEvent, null, DispatcherPriority.ApplicationIdle, dispatcher); }