public void DoRelease() { while (_keyPressedThread != null) { _cancellationTokenSource?.Cancel(); _keyPressedThread = null; } if (ActionForRelease == null) { /* * Must do this here as there are no ActionTypeKey for this button, otherwise Plugin would never get any event */ if (PluginManager.PlugSupportActivated && PluginManager.HasPlugin()) { PluginGamingPanelEnum pluginPanel = _streamDeckPanel.TypeOfPanel switch { GamingPanelEnum.StreamDeckMini => PluginGamingPanelEnum.StreamDeckMini, GamingPanelEnum.StreamDeck => PluginGamingPanelEnum.StreamDeck, GamingPanelEnum.StreamDeckV2 => PluginGamingPanelEnum.StreamDeckV2, GamingPanelEnum.StreamDeckMK2 => PluginGamingPanelEnum.StreamDeckMK2, GamingPanelEnum.StreamDeckXL => PluginGamingPanelEnum.StreamDeckXL, _ => PluginGamingPanelEnum.Unknown }; PluginManager.DoEvent( DCSFPProfile.SelectedProfile.Description, StreamDeckPanelInstance.HIDInstance, pluginPanel, (int)StreamDeckButtonName, false, null); } return; } while (ActionForRelease.IsRunning()) { _cancellationTokenSource?.Cancel(); } /* * Can ActionForRelease really be repeatable?? */ /*if (ActionForRelease.IsRepeatable()) * { * _cancellationTokenSource = new CancellationTokenSource(); * var threadCancellationToken = _cancellationTokenSource.Token; * ActionForRelease?.Execute(threadCancellationToken); * } * else * {*/ ActionForRelease.Execute(CancellationToken.None); //} }
public void DoRelease(CancellationToken threadCancellationToken) { _cancellationTokenSource.Cancel(); if (ActionForRelease == null) { return; } if (!ActionForRelease.IsRunning()) { ActionForRelease?.Execute(threadCancellationToken); } }