public void Run() { var res = MQueryCommand.TryUpdateLastStartTime(Id, DateTime.UtcNow); if (!res.IsComplete) { MLogger.Error($"3 - {res.Message}"); } List <Task> taskList = new List <Task>(); foreach (var compId in ShedulerTasksComputersLists.Select(x => x.ComputerId)) { taskList.Add(Task.Factory.StartNew(() => { var threadStep = GetStep(FirstStepId); if (threadStep == null) { MLogger.Error($"Error while getting first step of task (TaskId: {Id}, FirstStepId: {FirstStepId}). Operation won't be send."); } while (threadStep != null) { if (threadStep.OperationCheckIntervalMs > 0) { if (threadStep.Run(compId)) { Thread.Sleep(threadStep.OperationCheckIntervalMs); threadStep = CheckStepResultNew(threadStep); } else { return; } } else { if (threadStep.Run(compId)) { threadStep = GetStep(threadStep.OnOperationCompleteStep); } else { return; } } } })); MLogger.Debug($"Task for compId: {compId} added"); } MLogger.Debug($"Start multithread [taskList.ToArray()]"); try { Task.WaitAll(taskList.ToArray()); } catch (Exception ex) { MLogger.Error($"4 - {ex.ToString()}"); } MLogger.Debug($"Before \"TryUpdateLastEndTime\""); res = MQueryCommand.TryUpdateLastEndTime(Id, DateTime.UtcNow); if (!res.IsComplete) { MLogger.Error($"5 - {res.Message}"); } DateTime period = new DateTime(1889, 1, 1, 0, 0, 0); switch ((ShedulerTaskModes)Mode) { case ShedulerTaskModes.Once: res = MQueryCommand.TrySetTaskEnabled(Id, false); if (!res.IsComplete) { MLogger.Error($"6 - {res.Message}"); } period = new DateTime(1889, 1, 1, 0, 0, 0); break; case ShedulerTaskModes.Daily: period = DateTime.UtcNow.AddDays(1); break; case ShedulerTaskModes.Weekly: period = DateTime.UtcNow.AddDays(7); break; case ShedulerTaskModes.Monthly: period = DateTime.UtcNow.AddMonths(1); break; case ShedulerTaskModes.Hours: period = DateTime.UtcNow.AddHours(RepeatValue.HasValue ? RepeatValue.Value : 0); break; case ShedulerTaskModes.Minutes: period = DateTime.UtcNow.AddMinutes(RepeatValue.HasValue ? RepeatValue.Value : 0); break; } res = MQueryCommand.TryUpdateNextStartTime(Id, period); if (!res.IsComplete) { MLogger.Error($"7 - {res.Message}"); } }