Exemplo n.º 1
0
 private void OnVideoPlayerError(object sender, PlayerErrorEventArgs e)
 {
     SetBusy(false);
     model.IsPlaying = false;
     nativePlayer.Stop();
     ErrorOcurred?.Invoke(this, e.Message);
 }
        private async void MainLoop(Stream stream, CancellationToken token)
        {
            while (token.IsCancellationRequested == false)
            {
                try
                {
                    await Task.Delay(TimeSpan.FromSeconds(0.1));

                    while (messagesToSend.TryDequeue(out IAdminMessage msg))
                    {
                        Packet packet = this.adminPacketService.CreatePacket(msg);
                        await stream.WriteAsync(packet.Buffer, 0, packet.Size).WaitMax(TimeSpan.FromSeconds(2));
                    }
                }
                catch (Exception e)
                {
                    cancellationTokenSource.Cancel();
                    ErrorOcurred?.Invoke(this, e);
                    State = WorkState.Errored;
                }
            }
        }
        private async void MainLoop(Stream stream, CancellationToken token)
        {
            while (token.IsCancellationRequested == false)
            {
                try
                {
                    Packet packet = await WaitForPacket(stream, token);

                    IAdminMessage message = adminPacketService.ReadPacket(packet);
                    if (!token.IsCancellationRequested)
                    {
                        receivedMessages.Enqueue(message);
                    }
                }
                catch (Exception e)
                {
                    cancellationTokenSource.Cancel();
                    ErrorOcurred?.Invoke(this, e);
                    State = WorkState.Errored;
                }
            }
        }