Files
2025-11-21 08:48:01 +08:00

28 lines
885 B
C#

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);
}
}
}