public void Run(bool complete = true, int tasksToComplete = 0) { Status = ParseTaskStatus.Running; int index = 0; foreach (var task in Tasks) { if (!complete && index == tasksToComplete) { break; } index++; AsyncTaskСhanged?.Invoke(this, Source); task.Run(Source); AsyncTaskСhanged?.Invoke(this, Source); if (task.Status != ParseTaskStatus.Ok) { FailedTaskIndex = index - 1; Status = ParseTaskStatus.Failed; AsyncParseEnd?.Invoke(this, Source); return; } } Status = ParseTaskStatus.Ok; Source.ParseTime = TimeSpan.Zero; Tasks.ForEach(p => Source.ParseTime += p.Length); AsyncParseEnd?.Invoke(this, Source); }
public void Run(List <ParseTask> tasks, bool complete = true, int tasksToComplete = 0) { Tasks = tasks; Status = ParseTaskStatus.Running; index = 0; if (AsyncTaskPeriodical != null) { periodThread = new Thread( p => { while (true) { Thread.Sleep(UpdatePeriod); AsyncTaskPeriodical.Invoke(this, parser); } }); periodThread.Start(); } foreach (var task in Tasks) { if (!complete && index == tasksToComplete) { break; } index++; AsyncTaskСhanged?.Invoke(this, parser); Exception exception = null; try { task.Run(parser); } catch (Exception ex) { exception = ex; } AsyncTaskСhanged?.Invoke(this, parser); task.Error = exception; if (task.Status != ParseTaskStatus.Ok || exception != null) { FailedTaskIndex = index - 1; Status = ParseTaskStatus.Failed; periodThread?.Abort(); AsyncParseEnd?.Invoke(this, parser); return; } } Status = ParseTaskStatus.Ok; parser.ParseTime = TimeSpan.Zero; Tasks.ForEach(p => parser.ParseTime += p.Length); periodThread?.Abort(); AsyncParseEnd?.Invoke(this, parser); }