From 8db98fe1142211c9941d9c7d944394c5d7a33159 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期一, 21 六月 2021 09:17:53 +0800
Subject: [PATCH] 提交

---
 zhengcaioa/zhengcaioa/Timer/TimedBackgroundService.cs |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/zhengcaioa/zhengcaioa/Timer/TimedBackgroundService.cs b/zhengcaioa/zhengcaioa/Timer/TimedBackgroundService.cs
new file mode 100644
index 0000000..1389a5e
--- /dev/null
+++ b/zhengcaioa/zhengcaioa/Timer/TimedBackgroundService.cs
@@ -0,0 +1,42 @@
+锘縰sing Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System;
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace zhengcaioa.Timer
+{
+    public class TimedBackgroundService : BackgroundService
+    {
+        private readonly ILogger _logger;
+        
+
+        public TimedBackgroundService(ILogger<TimedBackgroundService> logger)
+        {
+            _logger = logger;
+        }
+        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+        {
+            _logger.LogInformation("MyServiceA is starting.");
+
+            //stoppingToken.Register(() => File.Create($"E:\\dotnetCore\\Practice\\Practice\\{DateTime.Now.Millisecond}.txt"));
+
+            while (!stoppingToken.IsCancellationRequested)
+            {
+                _logger.LogInformation("MyServiceA 寮�濮嬫墽琛�");
+
+                await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
+
+                _logger.LogInformation("缁х画鎵ц");
+            }
+
+            _logger.LogInformation("MyServiceA background task is stopping.");
+        }
+
+        public override void Dispose()
+        {
+            base.Dispose();
+        }
+    }
+}

--
Gitblit v1.9.1