From c3243e4c0c8a83afc1f6bfdf26fd997eda2650da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=94=84=E5=A4=B4?= Date: Tue, 14 May 2024 15:02:04 +0800 Subject: [PATCH] demo --- PclWorker.cs | 4 ++-- Program.cs | 14 ++++++-------- Worker.cs | 12 ++++++------ WorkerSynReport.csproj | 4 ++-- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/PclWorker.cs b/PclWorker.cs index ee6b498..8da0a4c 100644 --- a/PclWorker.cs +++ b/PclWorker.cs @@ -19,7 +19,7 @@ public class PclWorker:BackgroundService protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - _timer ??= new TimerX(DoPlc, "", 100, 1000); + _timer ??= new TimerX(DoPlc, "", 100, 10000); _timer.Async = true; // while (!stoppingToken.IsCancellationRequested) @@ -31,7 +31,7 @@ public class PclWorker:BackgroundService private void DoPlc(Object state) { - _logger.LogInformation("{Data}",DateTime.Now.ToFullString()); + // _logger.LogInformation("{Data}",DateTime.Now.ToFullString()); //todo 备份数据库 // using var scope = _scopeFactory.CreateScope(); diff --git a/Program.cs b/Program.cs index 716dbc6..c367ab0 100644 --- a/Program.cs +++ b/Program.cs @@ -8,16 +8,14 @@ XTrace.UseConsole(); IHost host = Host.CreateDefaultBuilder(args) .ConfigureServices(services => { - services.AddScoped(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;")); - - services.AddScoped(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;")); + services.AddScoped(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;Encrypt=false;")); + services.AddScoped(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;Encrypt=false;")); + + services.AddHostedService(); - services.AddScoped(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;")); - // services.AddHostedService(); + // services.AddScoped(); - services.AddScoped(); - - services.AddHostedService(); + //services.AddHostedService(); }) .UseAgentService(options => { diff --git a/Worker.cs b/Worker.cs index f3621b0..7c8facc 100644 --- a/Worker.cs +++ b/Worker.cs @@ -22,12 +22,12 @@ namespace WorkerSynReport { while (!stoppingToken.IsCancellationRequested) { - - await SynWetMixer(); await SynDry(); + await SynWetMixer(); + await SynGel(); - await Task.Delay(1000*30, stoppingToken); + await Task.Delay(1000*60, stoppingToken); } } @@ -59,7 +59,7 @@ namespace WorkerSynReport if (lsMain.Any()) { - XTrace.WriteLine("插入数据:{0}",lsMain.Count); + XTrace.WriteLine("湿混机插入数据:{0}",lsMain.Count); await dbContextHttp.InsertRangeAsync(lsMain); await dbContextHttp.InsertRangeAsync(lsMainDetail); } @@ -100,7 +100,7 @@ namespace WorkerSynReport if (lsMain.Any()) { - XTrace.WriteLine("插入数据:{0}",lsMain.Count); + XTrace.WriteLine("干混机插入数据:{0}",lsMain.Count); await dbContextHttp.InsertRangeAsync(lsMain); await dbContextHttp.InsertRangeAsync(lsMainDetail); await dbContextHttp.InsertRangeAsync(lsMixerDetails); @@ -150,7 +150,7 @@ namespace WorkerSynReport if (lsMain.Any()) { - XTrace.WriteLine("插入数据:{0}",lsMain.Count); + XTrace.WriteLine("糊化机插入数据:{0}",lsMain.Count); await dbContextHttp.InsertRangeAsync(lsMain); await dbContextHttp.InsertRangeAsync(lsMainDetail); await dbContextHttp.InsertRangeAsync(lsMixerDetails); diff --git a/WorkerSynReport.csproj b/WorkerSynReport.csproj index 2f0e125..8929a8b 100644 --- a/WorkerSynReport.csproj +++ b/WorkerSynReport.csproj @@ -13,12 +13,12 @@ - + - +