try-catch parallel operations

This commit is contained in:
IsWaffle 2024-05-18 12:46:44 -04:00
parent da36ea3438
commit 32d910473b
2 changed files with 154 additions and 136 deletions

View File

@ -298,6 +298,10 @@ namespace PatcherUtils
RaiseProgressChanged(0, fileCountTotal, "Generating deltas...");
try
{
Parallel.ForEach(targetFiles,
new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile =>
{
@ -349,6 +353,11 @@ namespace PatcherUtils
RaiseProgressChanged(filesProcessed, fileCountTotal,
$"{targetFile.FullName.Replace(TargetFolder, "...")}{extension}", AdditionalInfo.ToArray());
});
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
// remove all queued files that were found in the source files list
PatchLogger.LogInfo(":: Updating Source List ::");
@ -456,9 +465,12 @@ namespace PatcherUtils
fileCountTotal = deltaFiles.Count;
var patchingTokenSource = new CancellationTokenSource();
// foreach (FileInfo deltaFile in deltaDir.GetFiles("*", SearchOption.AllDirectories))
try
{
Parallel.ForEach(deltaDir.GetFiles("*", SearchOption.AllDirectories).ToList(),
new ParallelOptions() { MaxDegreeOfParallelism = 5, CancellationToken = patchingTokenSource.Token},
new ParallelOptions() { MaxDegreeOfParallelism = 5, CancellationToken = patchingTokenSource.Token },
deltaFile =>
{
switch (deltaFile.Extension)
@ -553,9 +565,15 @@ namespace PatcherUtils
++filesProcessed;
RaiseProgressChanged(filesProcessed, fileCountTotal, deltaFile.Name, AdditionalInfo.ToArray());
});
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
if (errorsQueue.Count > 0)
{
PatchLogger.LogError($"Error queue entry count: {errorsQueue.Count}");
if (!errorsQueue.TryDequeue(out PatchMessage error))
{
return new PatchMessage("Errors occurred during patching, but we couldn't dequeue them :(\n\nThere may be more information in the log", PatcherExitCode.PatchFailed);