初始化
This commit is contained in:
27
BLWLogProduce/Services/CPUDataCollect.cs
Normal file
27
BLWLogProduce/Services/CPUDataCollect.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user