private void ThreadedPress(CancellationToken threadCancellationToken) { var first = true; while (true) { if (_cancellationTokenSource.IsCancellationRequested) { break; } if (!ActionForPress.IsRunning()) { ActionForPress?.Execute(threadCancellationToken); } if (first) { Thread.Sleep(500); first = false; } else { Thread.Sleep(25); } } }
public void DoPress() { if (ActionForPress == null) { /* * Must do this here as there are no ActionTypeKey for this button, otherwise Plugin would never get any event. * Otherwise it is sent from ActionTypeKey together with key configs associated with the button. */ if (PluginManager.PlugSupportActivated && PluginManager.HasPlugin()) { PluginManager.DoEvent( DCSFPProfile.SelectedProfile.Description, StreamDeckPanelInstance.HIDInstance, StreamDeckCommon.ConvertEnum(_streamDeckPanel.TypeOfPanel), (int)StreamDeckButtonName, true, null); } return; } while (ActionForPress.IsRunning()) { _cancellationTokenSource?.Cancel(); } if (ActionForPress.IsRepeatable()) { _cancellationTokenSource = new CancellationTokenSource(); var threadCancellationToken = _cancellationTokenSource.Token; Debug.WriteLine("Creating Key Press Thread for Streamdeck"); _keyPressedThread = new Thread(() => ThreadedPress(threadCancellationToken)); _keyPressedThread.Start(); } else { ActionForPress.Execute(CancellationToken.None); } }
public void DoPress() { if (ActionForPress == null) { return; } while (ActionForPress.IsRunning()) { _cancellationTokenSource.Cancel(); } if (ActionForPress.IsRepeatable()) { _cancellationTokenSource = new CancellationTokenSource(); var threadCancellationToken = _cancellationTokenSource.Token; _keyPressedThread = new Thread(() => ThreadedPress(threadCancellationToken)); _keyPressedThread.Start(); } else { ActionForPress.Execute(CancellationToken.None); } }