You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

1 year ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win_in.Sfs.Basedata.Domain;
namespace Win_in.Sfs.Basedata.Caches;
public static class Cache
{
1 year ago
public static List<Bom> Boms = new List<Bom>();
public static async void BomsLifeCycle(int lifetime)
{
var reassigner = new Reassigner(DateTime.Now,new TimeSpan(0,5,0));
await reassigner.RunAsync(() => {
Boms.Clear();
}).ConfigureAwait(false);
}
1 year ago
}
1 year ago
public class Reassigner
{
private readonly TimeSpan _interval;
private DateTime _lasttime;
public Reassigner(DateTime lasttime, TimeSpan interval)
{
_lasttime = lasttime;
_interval = interval;
}
public async Task RunAsync(Action p_action)
{
while (true)
{
// 获取当前时间
var currentTime = DateTime.Now;
// 计算上次重新赋值到现在的时间间隔
var elapsed = currentTime - _lasttime;
// 检查时间间隔是否满足条件
if (elapsed >= _interval)
{
p_action();
// 重新赋值
//_value = await GetValueAsync();
// 更新最后更新时间
_lasttime = currentTime;
}
// 等待下一刻钟
await Task.Delay(_interval);
}
}
}