林豪 左 1 năm trước cách đây
mục cha
commit
eb44d1eefe
1 tập tin đã thay đổi với 32 bổ sung20 xóa
  1. 32 20
      WCS.Core/World.cs

+ 32 - 20
WCS.Core/World.cs

@@ -208,42 +208,52 @@ namespace WCS.Core
         private void Loop()
         {
             var sw = new Stopwatch();
-            while (!Stoped)
+            while (true)
             {
+                var title = GetType().GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;
+                ExLog(title.Description, 1);
                 this.Frame = DateTime.Now;
                 WorkTimes wt = new WorkTimes();
                 wt.Key = $"{this.Description} 周期:{Interval}";
                 sw.Restart();
+                ExLog(title.Description, 2);
                 BeforeUpdate();
+                ExLog(title.Description, 3);
                 Update(wt.Items);
-                //var wt1 = new WorkTimes();
-                //wt1.Key = "更新后处理内容";
-                //var sw1 = new Stopwatch();
-                //sw1.Restart();
+                ExLog(title.Description, 4);
                 AfterUpdate();
-                //sw1.Stop();
-                //wt1.Total = sw1.ElapsedMilliseconds;
-                //wt.Items.AddSafe(wt1);
                 sw.Stop();
+                ExLog(title.Description, 5);
                 var workTimes = (int)sw.ElapsedMilliseconds;
                 var ms = Interval - workTimes;
-                //sw.Start();
+
                 if (ms > 0)
                 {
                     Thread.Sleep(ms);//不要使用Task.Delay().Wait()
                 }
-                //sw.Stop();
-                //var total = sw.ElapsedMilliseconds;
+                ExLog(title.Description, 6);
                 wt.Total = workTimes;
                 FrameInfo(wt);
+                ExLog(title.Description, 7);
             }
         }
 
+        private void ExLog(string word, int msg)
+        {
+            var path = $"D:\\WCSLogs\\{DateTime.Now:yyyy-MM-dd}\\执行记录";
+            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+            File.AppendAllLines(Path.Combine(path, $"{word}.txt"), new[] { $"{DateTime.Now:yyyy-MM-dd hh:mm:ss:fffff}-----{msg}" });
+        }
+
         public void Stop()
         {
             Stoped = true;
         }
 
+        /// <summary>
+        ///  周期
+        /// </summary>
+        /// <param name="list"></param>
         private void Update(List<WorkTimes> list)
         {
             var wt = new WorkTimes();
@@ -330,10 +340,16 @@ namespace WCS.Core
             }
         }
 
+        /// <summary>
+        ///  周期前执行
+        /// </summary>
         protected virtual void BeforeUpdate()
         {
         }
 
+        /// <summary>
+        ///  周期后执行
+        /// </summary>
         protected virtual void AfterUpdate()
         {
         }
@@ -363,17 +379,13 @@ namespace WCS.Core
             }
 
             var msg = wt.GetInfo();
-            //if (wt.Total > 4000)
+
+            //if (wt.Total > 1500)
             //{
-            //    OnLog(Ltc.GetChannel(), $"周期超时记录:{msg}");
+            //    var path = $"D:\\WCSLogs\\{DateTime.Now:yyyy-MM-dd}\\超时记录";
+            //    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+            //    File.AppendAllLines(Path.Combine(path, "周期超时记录.txt"), new[] { $"{DateTime.Now:yyyy-MM-dd hh:mm:ss:fffff}-----周期超时记录:{msg}" });
             //}
-
-            if (wt.Total > 1500)
-            {
-                var path = $"D:\\WCSLogs\\{DateTime.Now:yyyy-MM-dd}\\超时记录";
-                if (!Directory.Exists(path)) Directory.CreateDirectory(path);
-                File.AppendAllLines(Path.Combine(path, "周期超时记录.txt"), new[] { $"{DateTime.Now:yyyy-MM-dd hh:mm:ss:fffff}-----周期超时记录:{msg}" });
-            }
             Console.WriteLine(msg);
 
             Console.ResetColor();