Commit 5aee2158 by lizefeng

修改缺货改零推送方式

parent 55c81992
...@@ -10,29 +10,31 @@ namespace ShortagePush ...@@ -10,29 +10,31 @@ namespace ShortagePush
{ {
public class ShortagePushBackgroundService : BackgroundService public class ShortagePushBackgroundService : BackgroundService
{ {
private Timer _timer;
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(5));
return Task.CompletedTask;
}
private void DoWork(object state) protected override Task ExecuteAsync(CancellationToken stoppingToken)
{ {
try Task.Factory.StartNew(() => {
while (true)
{ {
Console.WriteLine($"开始推送缺货数据任务,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); System.Console.WriteLine($"开始推送改零数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
new ReportServices().ShortagePush(); new ReportServices().ShortagePush();
System.Console.WriteLine($"结束推送改零数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
System.Console.WriteLine($"开始推送回货数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
new ReportServices().ReturnGoodsPush(); new ReportServices().ReturnGoodsPush();
Console.WriteLine($"结束推送缺货数据任务,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); System.Console.WriteLine($"结束推送回货数据,线程Id:{Thread.CurrentThread.ManagedThreadId}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
catch (Exception ex) Thread.Sleep(5 * 60 * 1000);
{
Console.WriteLine(ex.Message);
} }
});
return Task.CompletedTask;
} }
public override void Dispose() public override void Dispose()
{ {
base.Dispose(); base.Dispose();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment