
using System.Collections.Concurrent;
using CommonTools;

namespace BLWLogProduce.Services
{
    public class CPUDataCollect : BackgroundService
    {
        public static ConcurrentBag<double> CPU_Data = new ConcurrentBag<double>();
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            return Task.Factory.StartNew(async () =>
            {
                var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
                while (await timer.WaitForNextTickAsync(stoppingToken))
                {
                    Console.WriteLine("HostServiceTest_A is doing work.");
                    double d = CPUData.GetCPU();
                    CPUDataCollect.CPU_Data.Add(d);
                }

                Console.WriteLine("HostServiceTest_A task done.");

            }, TaskCreationOptions.LongRunning);
        }
    }
}
