
using System.Threading.Channels;
using Common;
using static CSRedis.CSRedisClient;

namespace BLWLogProduce.Services
{
    public class CRICS_P_C : BackgroundService
    {
        private static Channel<string> _messageChannel;

        public CRICS_P_C()
        {

        }
        public static async Task ConsumeMessagesAsync()
        {
            while (true)
            {
                if (_messageChannel.Reader.TryRead(out var nnn))
                {
                    //CSRedisCacheHelper.redis3.Subscribe(wireshark);
                }
            }
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                // 创建无界Channel
                _messageChannel = Channel.CreateUnbounded<string>();
                await ConsumeMessagesAsync();
                var wireshark = ("crics-udp-package", new Action<SubscribeMessageEventArgs>(async (args) =>
                {
                    try
                    {
                        await _messageChannel.Writer.WriteAsync("");
                    }
                    catch (Exception)
                    {

                    }
                }));

                CSRedisCacheHelper.redis3.Subscribe(wireshark);
            }
            catch (Exception)
            {

            }
        }
    }
}
