22 lines
471 B
C#
22 lines
471 B
C#
namespace MasstransferCommon.Scheduler;
|
|
|
|
/// <summary>
|
|
/// 延时定时任务
|
|
/// </summary>
|
|
public class DelayScheduler
|
|
{
|
|
private Timer _timer;
|
|
private Action _action;
|
|
|
|
public void Schedule(Action action, TimeSpan delay)
|
|
{
|
|
_action = action;
|
|
_timer = new Timer(TimerCallback, null, delay, Timeout.InfiniteTimeSpan);
|
|
}
|
|
|
|
private void TimerCallback(object? state)
|
|
{
|
|
_timer?.Dispose();
|
|
_action?.Invoke();
|
|
}
|
|
} |