Cancel DownloadChapter-Task on removal

This commit is contained in:
glax 2023-06-11 19:16:05 +02:00
parent fcd81f03b3
commit a0469f3145

View File

@ -207,8 +207,11 @@ public class TaskManager
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {removeTask}"); logger?.WriteLine(this.GetType().ToString(), $"Removing Task {removeTask}");
_allTasks.Remove(removeTask); _allTasks.Remove(removeTask);
if (removeTask.GetType() == typeof(DownloadChapterTask)) if (removeTask.GetType() == typeof(DownloadChapterTask))
{
_runningDownloadChapterTasks[(DownloadChapterTask)removeTask].Cancel();
_runningDownloadChapterTasks.Remove((DownloadChapterTask)removeTask); _runningDownloadChapterTasks.Remove((DownloadChapterTask)removeTask);
} }
}
public TrangaTask? AddTask(TrangaTask.Task taskType, string? connectorName, string? internalId, public TrangaTask? AddTask(TrangaTask.Task taskType, string? connectorName, string? internalId,
TimeSpan reoccurrenceTime, string? language = "en") TimeSpan reoccurrenceTime, string? language = "en")
@ -263,11 +266,12 @@ public class TaskManager
_allTasks.RemoveWhere(mTask => _allTasks.RemoveWhere(mTask =>
mTask.GetType() == typeof(DownloadNewChaptersTask) && mTask.GetType() == typeof(DownloadNewChaptersTask) &&
((DownloadNewChaptersTask)mTask).publication.internalId == publicationId && ((DownloadNewChaptersTask)mTask).publication.internalId == publicationId &&
((DownloadNewChaptersTask)mTask).connectorName == connectorName!); ((DownloadNewChaptersTask)mTask).connectorName == connectorName);
_allTasks.RemoveWhere(mTask => foreach(TrangaTask rTask in _allTasks.Where(mTask =>
mTask.GetType() == typeof(DownloadChapterTask) && mTask.GetType() == typeof(DownloadChapterTask) &&
((DownloadChapterTask)mTask).publication.internalId == publicationId && ((DownloadChapterTask)mTask).publication.internalId == publicationId &&
((DownloadChapterTask)mTask).connectorName == connectorName!); ((DownloadChapterTask)mTask).connectorName == connectorName))
DeleteTask(rTask);
} }
break; break;
} }