zoulei 1 year ago
parent
commit
baecbb974f

+ 1 - 0
Service/X1LeoTaskServer54/Service/TaskService.cs

@@ -391,6 +391,7 @@ namespace X1LeoTaskServer54.Service
         }
         private async Task StopTask(int taskID, EnumTaskStopType type, string stopReason)
         {
+            cts?.Cancel();
             await Task.Delay(2000);
             if (type == EnumTaskStopType.Properly)
             {

+ 1 - 0
Service/X2D1TaskServer54/Service/TaskService.cs

@@ -438,6 +438,7 @@ namespace X2D1NoRefTaskServer54.Service
         }
         private async Task StopTask(int taskID, EnumTaskStopType type, string stopReason)
         {
+            cts?.Cancel();
             await Task.Delay(2000);
             if (type == EnumTaskStopType.Properly)
             {

+ 1 - 0
Service/X2LeoTaskServer54/Service/TaskService.cs

@@ -432,6 +432,7 @@ namespace X2LeoTaskServer54.Service
         }
         private async Task StopTask(int taskID, EnumTaskStopType type, string stopReason)
         {
+            cts?.Cancel();
             await Task.Delay(2000);
             if (type == EnumTaskStopType.Properly)
             {

+ 1 - 0
Service/X3LeoTaskServer54/Service/TaskService.cs

@@ -391,6 +391,7 @@ namespace X3LeoTaskServer54.Service
         }
         private async Task StopTask(int taskID, EnumTaskStopType type, string stopReason)
         {
+            cts?.Cancel();
             await Task.Delay(2000);
             if (type == EnumTaskStopType.Properly)
             {

+ 1 - 0
Service/X3TaskServer54/Service/TaskService.cs

@@ -400,6 +400,7 @@ namespace X3TaskServer54.Service
         }
         private async Task StopTask(int taskID, EnumTaskStopType type, string stopReason)
         {
+            cts?.Cancel();
             await Task.Delay(2000);
             if (type == EnumTaskStopType.Properly)
             {

+ 1 - 1
XdCxRhDW.App/Controllers/LogController.cs

@@ -159,7 +159,7 @@ namespace XdCxRhDW.App.Controllers
                     {
                         LogTime = DateTime.Now,
                         LogType = EnumLogTypeDto.Info,
-                        Module = "平台",
+                        Module = Process.GetCurrentProcess().ProcessName,
                         Msg = $"用户删除了{delItemsReal.LongCount()}行日志"
                     });
                     return Success();

+ 11 - 5
XdCxRhDW.App/Controllers/TaskController.cs

@@ -16,6 +16,7 @@ using XdCxRhDW.Repostory;
 using XdCxRhDW.WebApi;
 using System.Threading;
 using Microsoft.Owin;
+using System.Diagnostics;
 
 namespace XdCxRhDW.App.Controllers
 {
@@ -63,18 +64,23 @@ namespace XdCxRhDW.App.Controllers
                     if (item.TaskState == EnumTaskState.Stopped)
                         Thread.Sleep(2000);
                     item.TaskState = EnumTaskState.Stopped;
+
+                    LogRes res = new LogRes()
+                    {
+                        LogTime = DateTime.Now,
+                        Module = Process.GetCurrentProcess().ProcessName,
+                        LogType = EnumLogType.Info,
+                        Msg = $"任务停止完成,ID={dto.ID},停止原因={dto.StopReason}",
+                    };
+                    db.LogRes.Add(res);
                     await db.SaveChangesAsync();
                 }
                 Messenger.Defalut.Pub("任务状态改变", dto.ID);
-                if (dto.StopType == EnumTaskStopType.Properly)
-                    await LogHelper.Info($"任务停止完成,ID={dto.ID},停止原因={dto.StopReason}");
-                else
-                    await LogHelper.Error($"任务停止完成,ID={dto.ID},停止原因={dto.StopReason}");
                 return Success();
             }
             catch (Exception ex)
             {
-                await LogHelper.Error($"任务停止异常.ID={dto.ID}", ex);
+                Serilog.Log.Error(ex, $"任务停止异常.ID={dto.ID}");
                 return Error(ex.Message);
 
             }

+ 18 - 22
XdCxRhDW.App/MainForm.cs

@@ -345,30 +345,26 @@ namespace XdCxRhDW
 
         private void StartProcess()
         {
-            Task.Run(() =>
+            KillProcess();
+            Process pro = new Process();
+            var servicesDir = Directory.GetDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Service\\"), "*", SearchOption.TopDirectoryOnly);
+            foreach (var item in servicesDir)
             {
-                KillProcess();
-                Process pro = new Process();
-                var servicesDir = Directory.GetDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Service\\"), "*", SearchOption.TopDirectoryOnly);
-                Parallel.ForEach(servicesDir, item =>
+                try
                 {
-                    try
-                    {
-                        string exeName = Path.GetFileNameWithoutExtension(item);
-                        string exeFile = $"{item}\\{exeName}.exe";
-                        pro.StartInfo.FileName = exeFile;
-                        pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
-                        pro.StartInfo.Arguments = $"http://127.0.0.1:{SysConfig.Config.HttpPort}";
-                        pro.Start();
-                    }
-                    catch (Exception ex)
-                    {
-                        Serilog.Log.Error(ex, $"启动【{item}】中的服务异常");
-                        DxHelper.MsgBoxHelper.ShowError($"启动【{item}】中的服务异常");
-                    }
-                });
-            });
-
+                    string exeName = Path.GetFileNameWithoutExtension(item);
+                    string exeFile = $"{item}\\{exeName}.exe";
+                    pro.StartInfo.FileName = exeFile;
+                    pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+                    pro.StartInfo.Arguments = $"http://127.0.0.1:{SysConfig.Config.HttpPort}";
+                    pro.Start();
+                }
+                catch (Exception ex)
+                {
+                    Serilog.Log.Error(ex, $"启动【{item}】中的服务异常");
+                    DxHelper.MsgBoxHelper.ShowError($"启动【{item}】中的服务异常");
+                }
+            }
         }
         private void KillProcess()
         {