Exemple #1
0
 private static void ReceiverChannelStatusChanged(object sender, EventArgs e)
 {
     recChanel = (IReceiverChannel)sender;
     Task.Run(async() =>
     {
         recStatus = await recChanel.GetStatusAsync();
     });
 }
Exemple #2
0
        private async void ListenForReceiverChanges(CancellationToken token)
        {
            try
            {
                _logger.LogInfo($"{nameof(ListenForReceiverChanges)}: Starting the receiver changes loop");
                await ListenReceiverChangesSemaphoreSlim.WaitAsync(token);

                await Task.Run(async() =>
                {
                    while (!token.IsCancellationRequested)
                    {
                        await Task.Delay(GetReceiverStatusDelay, token);
                        var status = await _receiverChannel.GetStatusAsync(_sender);
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }
                        TriggerVolumeEvents(status.Volume?.Level ?? 0, status.Volume?.IsMuted ?? false);
                    }
                }, token).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                if (e is TaskCanceledException || e is OperationCanceledException)
                {
                    return;
                }
                _logger.LogError($"{nameof(ListenForReceiverChanges)}: Unknown error occurred", e);
            }
            finally
            {
                _logger.LogInfo($"{nameof(ListenForMediaChanges)}: Receiver changes loop completed");
                if (ListenReceiverChangesSemaphoreSlim.CurrentCount == 0)
                {
                    ListenReceiverChangesSemaphoreSlim.Release();
                }
            }
        }